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()){
}
}
}
/**
* 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()){
}
}
}