aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Starting background process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Starting background process" Watch "Starting background process" New topic
Author

Starting background process

Narayanan Jayaraman
Ranch Hand

Joined: Apr 09, 2003
Posts: 52
How to start a background process from Swing application. In my swing application I start a background process thread by clicking a button. But When I close the application it also closes the thread. Any idea how to do it ?.
Thanks
Lee Barney
Ranch Hand

Joined: May 07, 2003
Posts: 37
Is this process to be a java process or a native process?
Narayanan Jayaraman
Ranch Hand

Joined: Apr 09, 2003
Posts: 52
This one is Java process.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Are you setting the default close operation of the frame to EXIT_ON_CLOSE? That just calls System.exit() when you close your frame and kills the JVM. Same thing as if you attached a WindowListener to your frame and called System.exit(). If you want your frame to go away, but the thread to keep running, either hide (setVisible( false ) or HIDE_ON_CLOSE) or get rid of ( dispose() or DISPOSE_ON_CLOSE) your frame on closing, and wait for your thread to finish before calling System.exit(). If you have a reference to the thread, you can simply call thread.join() to do this. Important point - You have to put the code to wait for your thread to end and then call System.exit()... you can't skip this part because once you start up a GUI application in Java you must call System.exit() specifically because the AWT Event thread won't let the JVM die on its own.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Narayanan Jayaraman
Ranch Hand

Joined: Apr 09, 2003
Posts: 52
I use dispose() method to close the frame. But the background process has to run forever. Is it possible to start the process in different JVM ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting background process