MyThread

来源:互联网 发布:广州入学积分怎么算法 编辑:程序博客网 时间:2024/06/04 01:08
package org.sf.thread;
/**
 * wait sleep wait必须在锁里面才可以被唤醒,wait 等待后是可以被唤醒,而sleep等待多长时间就多长时间
 * @author sfit0734
 *
 */
public class MyThread {
 public static void main(String[] args) {
  
  Runnable runnable = new Runnable() {
   
   @Override
   public void run() {
    // TODO Auto-generated method stub
     synchronized (this) {
      try {
      wait(6000);
     } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
      System.out.println("wait finished!");
     }
   }
  };
  
  Thread t = new Thread(runnable, "WATCHDOG");
     t.setDaemon(true);
     t.start();
    
     while(t.isAlive()){
      
     }
  
 }
 
 
}
0 0
原创粉丝点击