多线程实现间隔打印
来源:互联网 发布:jdbc连接数据库 编辑:程序博客网 时间:2024/05/16 11:07
public class TestThread{ public synchronized void x() { System.out.println("rgreighreiohgioer"); notify(); try{ wait(); }catch(InterruptedException e){ e.printStackTrace(); } } public synchronized void y(){ System.out.println("----------"); notify(); try{ wait(); }catch(InterruptedException e){ e.printStackTrace(); } } public static void main(String[] args){ TestThread t=new TestThread(); new ThreadA(t).start(); new ThreadB(t).start(); }}class ThreadA extends Thread{ private TestThread t; public ThreadA(TestThread t){ this.t=t; } @Override public void run(){ for(int i=0;i<100;++i){ t.x(); } }}class ThreadB extends Thread{ private TestThread t; public ThreadB(TestThread t){ this.t=t; } @Override public void run(){ for(int i=0;i<100;++i){ t.y(); } }}
//最后还是线程阻塞了23333
阅读全文
0 0
- 多线程实现间隔打印
- 使用wait和notify实现间隔打印
- 间隔 十秒 打印 “HelloWord”
- c++多线程实现循环打印ABC
- C#实现时间间隔
- RecyclerView 实现 间隔线
- android 打印时间间隔工具类
- 多线程之——实现循环打印"abc"
- 多线程和akka实现两个数组交替打印
- 多线程顺序打印ABC的三种实现---join方法
- 多线程交替打印ABC的多种实现方法
- 多线程之三个ABC线程实现循环打印100次
- 多线程交替打印ABC的多种实现方法
- 间隔一段时间实现页面跳转
- jQuery实现表格间隔色
- FusionChart实现奇偶间隔显示
- 日期-时间间隔的实现
- Java多线程--三个线程分别打印a,b,c.请用多线程实现循环打印15次abc
- web项目中jsp页面报错
- 【练习】银行排号程序
- C#总结---类
- 1.4、solrj的使用_代码开始
- selinux
- 多线程实现间隔打印
- SAS BASE&SAS EM 关联分析的学习 proc dmdb and proc assoc
- Python 练习实例6
- HDU 4393 Throw nails(技巧性模拟)
- POSIX和System V的比较/IPC函数汇总
- Android 二次封装网络加载框架
- 四、枚举,递推、迭代法初步学习
- 选择文件与获取选中文件绝对路径
- scrapy shell 爬取一些网站不响应