publicclassDemo10{publicstaticvoidmain(String[] args){// new Thread( new myYield(),"a").start();// new Thread( new myYield(),"b").start();
myYield s1 =newmyYield();newThread(s1,"a").start();newThread(s1,"b").start();}}classmyYieldimplementsRunnable{@Overridepublicvoidrun(){
System.out.println(Thread.currentThread().getName()+"开始运行");
Thread.yield();
System.out.println(Thread.currentThread().getName()+"结束运行");}}
Join
Join合并线程 待线程执行完后 再执行其他线程
类似插队
ublic classDemo11implementsRunnable{@Overridepublicvoidrun(){for(int i =0; i <10; i++){
System.out.println("VIP来了"+ i);}}publicstaticvoid main (String[] args)throws InterruptedException {
Demo11 s1 =newDemo11();
Thread thread =newThread(s1);
thread.start();for(int i =0; i <100; i++){
System.out.println("main"+ i);if(i ==50){
thread.join();}}}}