![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
线程通信
凌霄殿的大帝
这个作者很懒,什么都没留下…
展开
-
实现线程间的通信(一)
notify()和wait()实现: this.notify():随机唤醒单个等待线程。 this.wait():当前线程等待,wait()若无人唤醒,则一直等待;而Thread.sleep是睡眠一定时间后再次启动。 public class DemoNotify { public static void main(String[] args) { f...原创 2018-11-13 10:18:08 · 120 阅读 · 0 评论 -
实现线程间的通信(二)
非静态的同步方法的锁对象:this 静态的同步方法的锁对象是:该类的字节码对象 this.notify():唤醒单个等待的线程 this.notifyAll():唤醒所有等待的线程 /* * 1.在同步代码块中,用哪个对象锁,就用那个对象调用wait方法 * 2.为什么wait方法和notify方法可以定义在Object这类中 * 因为锁对象是...原创 2018-11-13 11:25:04 · 80 阅读 · 0 评论 -
线程组
package com.runtime; public class DemoThreadGroup { public static void main(String[] args) { MyRunnable m=new MyRunnable(); ThreadGroup tGroup=new ThreadGroup("new group"); ...原创 2018-11-13 11:40:02 · 71 阅读 · 0 评论 -
线程的五种状态
线程池: package com.thread; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class MyExecutor { public static void main(String[] args) { Execu...原创 2018-11-13 15:11:59 · 153 阅读 · 0 评论