I have a GUI application which needs to run silently in the background and keep collecting the information. It needs to display UI initially for entering the credentials and then occasionally for displaying the errors.
I understand that I cant run the GUI app as a service, so I thought of creating service just to launch the GUI application. So the first program is run as a service, which just starts the GUI application and then keeps listening for any information from the GUI app. Below is the code for the first application which launches the GUI application.
String path = Paths.get("D:\\Dempapp.jar").toAbsolutePath().normalize().toString();
String[] startOptions = new String[] {"javaw", "-jar", path};
Process p = new ProcessBuilder(startOptions).start();
Timer tempTimer = new Timer();
tempTimer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println((new Date()).toString());
}
},new Date(),10*1000);
When I run this, the GUI application is launched but freezes at some point with 5-10 seconds, so the GUI is never launched. However, if I kill the first application which launched the GUI application, the GUI shows up immediately, and then continues to work as expected. And I haven't yet started running the first application as a service yet, I am still running it from command line.
So is there any better way to launch this GUI application from a windows service?