thread1.java

来自「JAVA 2应用开发指南」· Java 代码 · 共 35 行

JAVA
35
字号
public class therad1 extends Thread{
   int no;
   public therad1(int i){
     no=i;
   }

   public void run(){
     for(int i=0;i<7;i++){
	  System.out.println("Run thread"+ no+"="+i);
       if(Thread.currentThread().getName().equals("t1"));{
         Thread.yield();
        /* try{
         sleep(100);
         }
         catch(InterruptedException e){}*/
       }       
     }
   }

   public static void main(String[] args) {
    therad1 t1=new therad1(1);
    therad1 t2=new therad1(2);
    therad1 t3=new therad1(3);
    t1.setPriority(Thread.MAX_PRIORITY);
    t2.setPriority(Thread.MIN_PRIORITY);
    t3.setPriority(Thread.MAX_PRIORITY);
    t1.setName("t1");
    t2.setName("t2");
    t3.setName("t3");
    t1.start();
    t2.start();
    t3.start();
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?