java学习(158):线程的常用方法yield,优先级
生活随笔
收集整理的這篇文章主要介紹了
java学习(158):线程的常用方法yield,优先级
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//線程
public class test102 extends Thread{public void run(){while (true){System.out.println("我是線程1"+this.getName());try {Thread.sleep( 1000 );}catch (InterruptedException e){e.printStackTrace();}}}
}
//線程
public class test103 extends Thread{public void run(){while (true){System.out.println("我是線程2"+this.getName());try {Thread.sleep( 1000 );}catch (InterruptedException e){e.printStackTrace();}}}
}
測試類
public class test105 {public static void main(String[] args){test102 one=new test102();test103 two=new test103();one.setName("線程1");one.setName( "線程2" );//設置線程的優先級two.setPriority( Thread.MAX_PRIORITY );one.setPriority( Thread.MIN_PRIORITY );//線程暫停thread.yieldone.start();two.start();System.out.println( "我是主方法" );} }運行結果
總結
以上是生活随笔為你收集整理的java学习(158):线程的常用方法yield,优先级的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么安装redhat linux操作系统
- 下一篇: Collections.unmodifi