msabir1
Posts: 3
Joined: Fri Jan 20, 2006 3:52 pm

CPU goes to 100% when java program is installed as a service

I am evaluating AdvacnedInstaller for using it to install Java based programs on Windows platform.

I found that it runs great if you install it as a program. However, when I install it as a Windows Service, it does run but my CPU utilization goes to 100%.

Here is the code, I am using to create Java Service:

public class JavaService {
public static boolean isRunning;

// This method is called by AdvancedInstaller when it starts the Windows service
public static void main(String[] args){
try {

// Start the tomcat server
TomCatEmb.main(null);
Thread.sleep(1000);
isRunning=true;
while (isRunning){
}

} catch (Exception e) {
e.printStackTrace();
}
}

// This method is called by AdvancedInstaller when it stops the Windows service
public static void stop(){
TomCatEmb.stopServer();
isRunning=false;
}
}
Mike
Posts: 292
Joined: Wed Jun 01, 2005 10:50 am
Location: Craiova, Romania
Contact: Website

Hi,

This is because the while loop take control of the processor. You could try to call the sleep method inside the loop too. This way the processor only checks from time to time whether the service is stopped and releases the processor in the meantime.

Regards,
Mihai
Mihai Bobaru
Advanced Installer Team
http://www.advancedinstaller.com

Return to “Common Problems”