您的位置:首页 > 编程语言 > Java开发

java线程以睡眠方式等待信号量的到来

2012-04-20 14:36 176 查看
public class Test extends Thread{

public static void main(String[] args) {

Test test=new Test();

test.start();

}

public void run(){

boolean time=false;

while(true){

if(time==true){

System.out.println("here");

}else{

System.out.println("come");

}

try {

Thread.sleep(5000);

time=true; //发送信号量

} catch (InterruptedException e) {

System.out.println("线程错误");

e.printStackTrace();

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: