线程同步通信
来源:互联网 发布:网站视频分段播放 php 编辑:程序博客网 时间:2024/05/22 00:50
package itcast.thread;
/*
*
*/
public class TraditionalThreadCommunication {
public static void main(String[] args) {
TraditionalThreadCommunication t = new TraditionalThreadCommunication();
final Business b = t.new Business();
new Thread(new Runnable() {
public void run() {
for(int i=1;i<=50;i++){
b.sub(i);
}
}
}).start();
for(int i=1;i<=50;i++){
b.main(i);
}
}
public class Business{
private boolean shouldSub = true;
public synchronized void sub(int n){
while(!shouldSub){
try {
this.wait();//用同步监视器对象 this
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(int i=1;i<=10;i++){
System.out.println("sub thread sequence of " + i + ", loop of " + n);
}
shouldSub = false;
this.notify();
}
public synchronized void main(int n){
while(shouldSub){
try {
this.wait();//一定要用同步监视器对象 this
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(int i=1;i<=100;i++){
System.out.println("main thread sequence of " + i +", loop of "+ n);
}
shouldSub = true;
notify();
}
}
}
- 线程通信和同步
- 线程同步通信
- 同步,线程通信,lock
- 线程同步通信
- 线程之同步通信
- 线程同步通信
- 线程同步与通信
- 线程同步、通信
- 线程 进程 同步 通信
- Thread02:线程同步通信
- 进程通信&线程同步
- 4、线程同步通信
- 线程同步--线程间通信
- 线程同步--线程间通信
- 线程同步和线程通信
- 5.9 线程通信的同步
- 进程线程同步 进程通信
- JAVA线程同步、通信、中断
- Linux进程的实际用户ID和有效用户ID
- android学习指南
- vi 查找替换大全
- 大二的汇编,让人云里雾里!!!
- SAP传输系统TMS的配置和实例
- 线程同步通信
- 小米越来越不靠谱了
- smoj-1042数字三角形
- 编程之美的诱惑
- How Tomcat Works学习笔记<六>
- 我java启蒙老师 郝斌老师
- Android 让adb logcat打印内核调试信息
- Linux的特殊文件权限
- android中的回调举例:在surfaceview中结束宿主activity