File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Stopping a thread via command line Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Stopping a thread via command line" Watch "Stopping a thread via command line" New topic
Author

Stopping a thread via command line

mrybicki
Greenhorn

Joined: Jan 04, 2002
Posts: 1
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

Joined: Mar 15, 2000
Posts: 411
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

Joined: Jan 06, 2002
Posts: 111
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.


" Veni, vidi, vici "<br />" I came, I saw, I conquered "
 
 
subject: Stopping a thread via command line
 
Threads others viewed
About stop the RMI server
Java threads
why it prints the statement in wrong order or fashion?
Tomcat Server Running Status
Scheduled Task
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com