• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

stopping a java program

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a java program that will be constantly running and can only be stopped by user intervention. I would like to know how do I go about stopping a java program in such a fashion that it performs a few steps first then stops after it gets some kind of signal.

thanks
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a core console based program, then you can stop it through pressing ctrl+c key.
 
Gamb Rockwell
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that ctrl + c will allow me to perform a few steps then quit, I think it just kills the app. I am looking for a way to tell the app to quit but finish its current job before quitting.
 
Sanju Thomas
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you can use System.exit(0) in the program.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a swing/ awt program, you may add an interupt-button or add a keylistener or a menuentry or ...
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said: "... be stopped by user intervention. ", and "... after it gets some kind of signal."

You need to be clear what kind of user intervention you are trying to use as the signal. If you are talking about a key stroke, sorry, Java is not designed to implement command console interactions. You picked a wrong language. However, if you are talking about a button/link/image click/onMouseOver/whatever events on an AWT/Swing/HTML UI, surely you can do it easily: you need to have a method to handle that event, and that method does your final steps before exit(0).
 
Do not set lab on fire. Or this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic