Results 1 to 4 of 4

Thread: Threads. Preemption not working.

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Question Threads. Preemption not working.

    Once T3 starts it should run to completion with all current running threads yielding until then. This does not seem to be the case though. Any ideas why??? Thanks.
    Code:
    public class PreemptTest{
     public static void main(String[] args){
      Thread t1 = new Thread(new T(), "t1"); 
      Thread t2 = new Thread(new T(), "t2"); 
      Thread t3 = new Thread(new T(), "t3"); 
      t1.start(); 
      t2.start();
      t3.setPriority(Thread.currentThread().getPriority() + 1); 
      t3.start();
     }
    }
    
    class T implements Runnable{
     private int square; 
     
     public void run(){
      for(int i = 1; i < 5; i++){
       square = i * i; 
       System.out.println("Thread " + Thread.currentThread().getName() +
    	" has a priority of " + Thread.currentThread().getPriority() +
    	 ": " + square);   
      }
     } 
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width