This discussion is archived
3 Replies Latest reply: Jan 17, 2013 9:34 PM by 852617 RSS

Stop the running Thread

852617 Newbie
Currently Being Moderated

i am calling the thread .in the midlle of running thread i have to stop the thread .please help me .

my senario like . I am calling the scripts . i am wating certain period to complete the script exection . if the scripts are not available its still wating for a long time . so i am using the thread to execute the scripts and (main thread )checking each duration is completed or not . if the duration completed i am stoping the thread with Thread.Stop() method . but the thread still is alive . next time when i call Thread.Start() its throwing "java.lang.IllegalThreadStateException".
please help me this .
Thanks in advance

public class TestCaseScriptProcessor extends Thread {

public String execute(){

TestCaseScriptProcessor caseScriptProcessor = new TestCaseScriptProcessor();

caseScriptProcessor .start();// second time throwing java.lang.IllegalThreadStateException.

while (!isExpired) {


public void run() {


Edited by: 849614 on Jan 17, 2013 6:17 AM

Edited by: 849614 on Jan 17, 2013 6:22 AM
  • 1. Re: Stop the running Thread
    gimbal2 Guru
    Currently Being Moderated
    Don't give only half the information. Post the -exact- error you're getting, including the message and the stack trace.
  • 2. Re: Stop the running Thread
    805574 Newbie
    Currently Being Moderated
    What exactly are you trying to do? Calling Thread.stop( ) is inherently a bad idea (see the Javadocs).

    You are getting a IllegalStateException because Thread.stop( ) kills the thread, you would need to create a new thread to resume execution.

    If what you are trying to do is pause execution, you probably want to redesign your thread's tasks into smaller chunks that can be launched separately. Alternatively, have the thread check it's interrupted state and if a flag was set block on a monitor until you want it to resume execution.
  • 3. Re: Stop the running Thread
    852617 Newbie
    Currently Being Moderated

    Thanks for u r suggestion i am getting

         at java.lang.Thread.start(Unknown Source)


  • Correct Answers - 10 points
  • Helpful Answers - 5 points