Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove System.exit to avoid strange behavour. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions org.boris.winrun4j/java/src/org/boris/winrun4j/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@
public class MainService implements Service
{
private String serviceClass = INI.getProperty("MainService:class");
private volatile boolean shutdown = false;

public int serviceMain(String[] args) throws ServiceException {
public int serviceMain(final String[] args) throws ServiceException {
try {
Class c = Class.forName(serviceClass);
Method m = c.getMethod("main", String[].class);
m.invoke(null, (Object) args);
final Method m = c.getMethod("main", String[].class);
// Create a thread to run the service in, and use this thread to monitor it.
Thread t = new Thread() {
public void run() {
try {
m.invoke(null, (Object) args);
} catch (Exception e) {
}
shutdown = true;
}
};
t.start();
while (!shutdown) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
}
} catch (Exception e) {
throw new ServiceException(e);
}
Expand All @@ -30,7 +46,7 @@ public int serviceRequest(int control) throws ServiceException {
switch (control) {
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
System.exit(0);
shutdown = true;
break;
default:
break;
Expand Down