Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stopping a thread via command line

 
mrybicki
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a programmer with enough java knowledge to ge t my face slapped. Although this is a thread problem, I'm not sure if I should post here or in the general group.
I want to desgin a thread that the user can start/stop at a command prompt on a Sun box. The basic logic would be the user runs ./startup.sh it starts and ./shutdown.sh it stops. The basic logic I'm using is this:
public static void main(String args[])
{
if(args.length==1)
{
if(args[0].trim().toUpperCase().equals("SHUTDOWN"))
{
isDone = true;
...
}
}
else
{
isDone = false;
...
}
}
Using the java documentation as a guide, I trying to use a flag variable to stop the thread. I want the flag variable to be "static"; when I call shutdown, the thread is still there.
Any tips/ideas would be appreciated. Thanks.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little unsure of you question but would using a while loop help?

The Thread will then stop running if the 'something' conditon is true.
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call the thread's interrupt() method when you want it to stop. In the implementation code of the thread, catch InterruptedException and exit there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic