(多线程)OutPut
来源:互联网 发布:在哪里注册域名比较好 编辑:程序博客网 时间:2024/05/16 01:02
package duoxiancheng;class Res {String name;String sex;boolean flag=false;}class Put implements Runnable{Res r;Put(Res r){this.r=r;}public void run(){int x=1;while(true){synchronized(r){if(!r.flag){if(x==1){r.name="chenhong";r.sex="nv";}else{r.name="王";r.sex="男";}}r.flag=true;r.notify();try {r.wait();} catch (InterruptedException e) {// TODO 自动生成的 catch 块e.printStackTrace();}}x=(x+1)%2;} }}class Out implements Runnable{Res r;Out(Res r){this.r=r;}public void run(){while(true){synchronized(r){if(r.flag)System.out.println(r.name+" "+r.sex);r.flag=false;r.notify();try {r.wait();} catch (InterruptedException e) {// TODO 自动生成的 catch 块e.printStackTrace();}}}}}public class OutPut{public static void main(String[] args) {Res s=new Res();Put p=new Put(s);Out o=new Out(s);Thread d1=new Thread(p);Thread d2=new Thread(o);d1.start();d2.start();}}
0 0
- (多线程)OutPut
- output
- Output
- output
- Output
- 样式输出(Styling output)
- java IO接口(output)
- 文件输入输出(Input/Output with files)
- Input and Output(easy to use)
- IPO(INPUT PROCESS OUTPUT)图
- print系列函数(formatted output conversion)
- Java IO(Input/Output)----File
- 控制台输出水平(Console output levels)
- 黑马程序员- IO(Input- Output)(一)
- (一)Intellij output 中文乱码
- c++教程(六:Basic Input/Output)
- I/O(input/output)是什么意思?
- php 输出缓冲控制(Output Control )
- (多线程)ThreadTicketDemo1
- Android编程的根基,你必须遵守,这就是法律
- Yum 和 Apt 的使用和对比
- cocos2d-x的回调函数
- 解决mysql保存中文数据乱码
- (多线程)OutPut
- codeforces-611C-New Year and Domino
- 【LeetCode OJ 090】Subsets II
- ajax的4种常用请求方式
- CF #343 div2 D Babaei and Birthday Cake dp+线段树维护+(离散)
- JVM 参数介绍
- 第五届蓝桥杯 软件类省赛真题 第八题:兰顿蚂蚁
- C++ 单例模式实现代码
- quick-cocos2d-x 图片资源加密