Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

    Post Procedure to start Thread?

    What is the procedure to start a thread back after it loop value become false?

    i mean

    Java Code:
     public void run()
             { 
             while(flag)
               --------
              }
             flag = false;

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    you cant. After run() method completes, the thread is dead and cannot be re-started. You'll have to create a new object and start another thread.

    Why would you want to do this though? If you're trying to take care of pause/resume situation, the following code works for me:

    Java Code:
    class MyThread implements Runnable {
      private Thread theThread;
      private boolean isPaused;
      
      public void start() {
        isPaused = false;
        isRunning = true;
        theThread = new Thread(this);
        theThread.start();
      }
      public void shutdown() {
        isRunning=false;
        theThread.interrupt();
        this.join();
      }
      public void pause() {
        isPaused = true;
      }
      public void resume() {
        isPaused = false;
        synchronized(this) {
          this.notify();
        }
      }
      public void run() {
        while(isRunning) {
          synchronized(this) {
            while(isPaused && isRunning) {
              try {
                this.wait();
              } catch (InterruptedException ex) {
                // ignore
              }
            }
          }
          if(isRunning) {
            // do actual work here
          }
        }
      }
    }

  3. #3
    Join Date
    Mar 2010
    Posts
    23
    Rep Power
    0

Similar Threads

  1. call a pl/sql procedure through a jsp page
    By mudit222 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 04-20-2010, 09:02 PM
  2. Replies: 0
    Last Post: 02-03-2010, 09:20 AM
  3. stored procedure
    By sankarigopi in forum JDBC
    Replies: 1
    Last Post: 11-13-2008, 05:53 PM
  4. My thread will not start
    By markyoung1984 in forum Threads and Synchronization
    Replies: 4
    Last Post: 10-03-2008, 07:32 PM
  5. OutOfMemoryError: Unable to Start New Native Thread
    By edwin11 in forum Advanced Java
    Replies: 0
    Last Post: 11-16-2007, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •