IntelliJ Java IDE
The moose likes Threads and Synchronization and the fly likes How to Kill a Threan and re run it? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to Kill a Threan and re run it?" Watch "How to Kill a Threan and re run it?" New topic
Author

How to Kill a Threan and re run it?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 304
I have a program which run on thread now I have made a GUI interface to run the same. There I have 3 option - Start,Stop,Rerun.
I want to start the thread and would like to rerun it if i stop the same. I am trying following code but it stops but not able to rerun it rathermy application do System.exit(0)?
WHere I am wrong? Could you pl help me?
Code:-
----------

regards,
Arun
[CODE tags inserted -- PdH]
[ February 05, 2002: Message edited by: Peter den Haan ]
Alex Zhang
Ranch Hand

Joined: Apr 19, 2001
Posts: 68
Actually, thread cannot be restart once it has been stopped! :roll: So U'd better add a while loop and use the boolean field to control the thread!
Mehul Sanghvi
Ranch Hand

Joined: Feb 04, 2002
Posts: 134
Dear Arun,
As mentioned earlier you cannot rerun a thread after interrupting it...
Your code for interuppt button would remain the same as for your stop and rerun button i tried out the following code which i think may help you out..
CODE:

Regards,
Mehul.....
[CODE tags inserted -- PdH]
[ February 05, 2002: Message edited by: Peter den Haan ]
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Alternatively, you can rewrite your code as a Runnable. To restart, you run your Runnable with a fresh Thread.
- Peter
 
IntelliJ Java IDE
 
subject: How to Kill a Threan and re run it?
 
Threads others viewed
why this error
Why I can't write in a loop
interrupt
Strange Error [java.lang.ArrayIndexOutOfBoundsException]
ServerSocket problem w/ Jeode EVM on iPaq
developer file tools