package threadmethod.priority;publicclassSubThreadextendsThread{@Overridepublicvoidrun(){long begin = System.currentTimeMillis();long sum =0;for(int i =0; i <100000000; i++){
sum = sum+i;this.yield();}long end = System.currentTimeMillis();long time = end-begin;
System.out.println(this.getName()+"用时:"+time);}}
package threadmethod.yeild;publicclassSubThreadextendsThread{@Overridepublicvoidrun(){long begin = System.currentTimeMillis();long sum =0;for(int i =0; i <100000000; i++){
sum = sum+i;this.yield();}long end = System.currentTimeMillis();long time = end-begin;
System.out.println("用时:"+time);}}
package threadmethod.yeild;publicclassTest{publicstaticvoidmain(String[] args){
SubThread sb1 =newSubThread();
sb1.start();long begin = System.currentTimeMillis();long sum =0;for(int i =0; i <100000000; i++){
sum = sum+i;}long end = System.currentTimeMillis();long time = end-begin;
System.out.println("main用时:"+time);}}/*
输出
main用时:35
用时:8470
*/