Win a copy of The Career Toolkit this week in the Jobs Discussion forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Starting background process

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this process to be a java process or a native process?
 
Narayanan Jayaraman
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This one is Java process.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Narayanan Jayaraman
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic