GitHub - hellojavaio/java-concurrent-programming-explain
Repository navigation
java-concurrent-programming-explainPublic
About
No description or website provided.Topics
concurrent concurrent-programming explain javaResources
Readme License Activity Custom propertiesStars
0 starsWatchers
1 watchingForks
0 forks Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
11 Commits
View commit history for this file.
Folders and files
| Name | Name | Last commit message | Last commit date |
|---|---|---|---|
| .idea | .idea | ||
| module1 | module1 | ||
| .gitignore | .gitignore | ||
| AQS_doc.md | AQS_doc.md | ||
| LICENSE.png | LICENSE.png | ||
| README.md | README.md | ||
| java-concurrent-programming-explain.iml | java-concurrent-programming-explain.iml | ||
Repository files navigation
java-concurrent-programming-explain
Demo
Thread.join()
- 子线程执行完成才执行主线程
- ThreadJoinTest
CountDownLatch
- 所有子线程完成了阻塞
count计数之后就开始调用主线程的latch.await()之后的方法 - CountDownLatchTest
CyclicBarrier
CountDownLatch & CyclicBarrier
-
CountDownLatch和CyclicBarrier都能够实现线程之间的等待,只不过它们侧重点不同: -
CountDownLatch一般用于某个线程A等待若干个其他线程执行完任务之后,它才执行; -
而
CyclicBarrier一般用于一组线程互相等待至某个状态,然后这一组线程再同时执行; -
另外,
CountDownLatch是不能够重用的,而CyclicBarrier是可以重用的。
Semaphore
Semaphore其实和锁有点类似,它一般用于控制对某组资源的访问权限。- 初始化时设置大小, 线程每次获取和存放回去都有数量可选。
ForkJoin
- 讲任务分割最后汇集结果,类似排序中的归并