• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Kill a Threan and re run it?

 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, you can rewrite your code as a Runnable. To restart, you run your Runnable with a fresh Thread.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!