![](https://img-blog.csdnimg.cn/20190927151132530.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
多线程
文章平均质量分 62
轻井泽惠。
我阿惠
展开
-
通过volatile的可见性使线程按顺序执行(cas)
volatile static int flag=0; //#region public static void main(String[] args) throws Exception { int num=100; for (int i = 0; i < 100; i++) { int finalI = i; new Thread(()->{ while(true){原创 2022-02-02 23:20:16 · 464 阅读 · 0 评论 -
线程顺序执行的几种方式
线程顺序执行的几种方式实现1.使用线程的join方法使用线程的join方法2.使用主线程的join方法3.使用线程的wait方法4.使用线程的线程池方法8.使用Sephmore(信号量)实现线程按顺序运行 面试官:线程顺序执行,这么多答案你都答不上来? (qq.com) [1] 使用线程的join方法 [2] 使用主线程的join方法 [3] 使用线程的wait方法 [4] 使用线程的线程池方法 [5] 使用线程的Condition(条件变量)方法 [6] 使用线程的CountDownLatch(倒计数)方转载 2021-06-28 13:47:56 · 266 阅读 · 0 评论