6 Replies Latest reply: Sep 2, 2011 2:09 PM by 884440 RSS

    Pausing a running thread to start another thread

    428110
      Hi Everyone,
      I have three threads. One of the Threads run very critical processes So I would like this critical thread to run at all times irrespective of whether the other threads are running or not. My Current code "As shown below" starts all the three threads together which is ok but if records for processing are available for the critical thread, I want to interrupt the running thread, run the critical thread then go back to the thread that was interrupted and continue running it.
      The critical thread is in bold text below.


      Thread mainThread = new Thread();
      while (!Thread.currentThread().isInterrupted()) {
      try {
      *//THIS IS THE CRITICAL THREAD*
      moveSms p5 = new moveSms("p5");
      Thread p5t = new Thread(p5, "p5");
      p5t.setPriority(10);
      System.out.println("Starting Thread p5");
      p5t.start();



      moveSms p3 = new moveSms("p3");
      Thread p3t = new Thread(p3, "p3");
      p3t.setPriority(8);
      System.out.println("Starting Thread p3");
      p3t.start();
      p3t.sleep(10000);


      moveSms p1 = new moveSms("p1");
      Thread p1t = new Thread(p1, "p1");
      p1t.setPriority(6);
      System.out.println("Starting Thread p1");
      p1t.start();
      p1t.sleep(30000);

      } catch (InterruptedException ex) {
      System.out.println("InterruptedException: " + ex.getMessage());
      Logger.getLogger(moveSms.class.getName()).log(Level.SEVERE,null, ex);
      }

      Any Help will be appreciared