摘要: 如何保证主线程在副线程执行结束后才会执行结束,这里使用CountDownLatch //设置三个线程需要执行 CountDownLatch latch = new CountDownLatch(3); //每调用一次数值减1,当count为0,代表全部线程执行结束 latch.countDown() 阅读全文
posted @ 2022-12-22 20:00 不忘初心2021 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 需要的依赖 <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.9</version> </dependency> StopWatch started 阅读全文
posted @ 2022-12-22 20:00 不忘初心2021 阅读(23) 评论(0) 推荐(0) 编辑
摘要: Semaphore可以限制单个时间内允许活跃的线程数 //同一时间段允许3个线程活跃,非公平的模式 Semaphore semaphore = new Semaphore(3,false); //这里表示拿到一份资源,剩下只有2份资源可用了 semaphore.acquire(); //这里表示释放 阅读全文
posted @ 2022-12-22 19:59 不忘初心2021 阅读(25) 评论(0) 推荐(0) 编辑