管程是个什么概念?请高手结合wait和notify函数解释一下好吗?100分! 管程是指由synchronized修饰的线程 在同一时间内只能有一个线程 对该方法进行访问只有当一个线程结束对该方法的访问后 下一个线程才能对其访问 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 找一本java书籍看看吧,多线程那一部分内容,将使你想要弄明白的地方! wait是暂停一个线程notify继续进程例如:(尚未测试)class a extends Thread{ boolean st=false; //线程处于启动状态 a(String tn){ super(tn); //线程名称 start(); } public void run() throws Exception{ for (int i=0;i<50;i++){ System.out.println(i); Thread.sleep(100) synchronized(this){ //处理线程同步 while(st){ wait(); //暂停线程 } } } } public void stopT(){ st=true; } public void startT(){ //叫醒线程 st=false; notify(); }}运用------------------------------------------------public class userThread{ public static void main(String[] args) throws Exception{ a t1=new a("Thread1"); a t2=new a("thread2"); t1.stopT(); Thread.sleep(500); t1.startT(); }} Java里的wait(),notify()以及notifyAll()涉及到parallel programming里的Monitor概念,找一本这方面的书看看,就能更深刻地理解这些函数的运用了. 有没有JAVA 与ASP 通用的base64加密解密 急,很简单的代码,但就是解决不了 FileReader与FileWriter读写"*.txt"的问题 请问在一个页面表单里 如何用javascript调用exe文件 望高手指点 写出代码 有意思~~ 哪位能提供下载Java语言和库及其用户帮助手册的具体URL(最好能是中文版的)?感激! 一个关于JScrollPane的简单问题,送分!! 一个问题!急! 如何使用HttpURLConnection类?(紧急) 谁知道jbuilder5的s/n和key,请告诉我,不胜感激。 appletviewer初级问题 高分征求各种棋类游戏算法或程序
wait是暂停一个线程
notify继续进程
例如:(尚未测试)
class a extends Thread{
boolean st=false; //线程处于启动状态
a(String tn){
super(tn); //线程名称
start();
}
public void run() throws Exception{
for (int i=0;i<50;i++){
System.out.println(i);
Thread.sleep(100)
synchronized(this){ //处理线程同步
while(st){
wait(); //暂停线程
}
}
}
}
public void stopT(){
st=true;
}
public void startT(){ //叫醒线程
st=false;
notify();
}
}运用------------------------------------------------
public class userThread{
public static void main(String[] args) throws Exception{
a t1=new a("Thread1");
a t2=new a("thread2");
t1.stopT();
Thread.sleep(500);
t1.startT();
}}