├── source
├── 02-Asynchronous Programming
│ ├── ch02_04
│ │ ├── .idea
│ │ │ ├── .name
│ │ │ ├── .gitignore
│ │ │ ├── misc.xml
│ │ │ ├── modules.xml
│ │ │ └── workspace.xml
│ │ ├── ch02_04.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── CompletableFutureDemo5.java
│ │ │ ├── CompletableFutureDemo4.java
│ │ │ ├── CompletableFutureDemo2.java
│ │ │ ├── CompletableFutureDemo3.java
│ │ │ └── CompletableFutureDemo1.java
│ ├── ch02_02
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── src
│ │ │ ├── OtherTask.java
│ │ │ ├── TimeConsumingTask.java
│ │ │ └── Main.java
│ │ ├── ch02_02.iml
│ │ └── .gitignore
│ ├── ch02_05
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── vcs.xml
│ │ │ ├── misc.xml
│ │ │ └── modules.xml
│ │ ├── src
│ │ │ ├── StepFourSolution.java
│ │ │ ├── StepTwoSolution.java
│ │ │ ├── StepThreeSolution.java
│ │ │ ├── SumOfSquaresTask.java
│ │ │ ├── StepOneSolution.java
│ │ │ └── SumOfEvenTask.java
│ │ ├── ch02_05.iml
│ │ └── .gitignore
│ └── ch02_06
│ │ ├── ch02_06b
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── misc.xml
│ │ │ ├── vcs.xml
│ │ │ └── modules.xml
│ │ ├── src
│ │ │ ├── StepFourSolution.java
│ │ │ ├── StepTwoSolution.java
│ │ │ ├── StepThreeSolution.java
│ │ │ ├── StepOneSolution.java
│ │ │ ├── SumOfSquaresTask.java
│ │ │ └── SumOfEvenTask.java
│ │ ├── ch02_06b.iml
│ │ └── .gitignore
│ │ └── ch02_06e
│ │ ├── .idea
│ │ ├── .gitignore
│ │ ├── vcs.xml
│ │ ├── misc.xml
│ │ └── modules.xml
│ │ ├── ch02_06e.iml
│ │ ├── .gitignore
│ │ └── src
│ │ ├── SumOfSquaresTask.java
│ │ ├── SumOfEvenTask.java
│ │ ├── StepOneSolution.java
│ │ ├── StepTwoSolution.java
│ │ ├── StepThreeSolution.java
│ │ └── StepFourSolution.java
├── 03-Executors
│ ├── ch03_03
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ ├── workspace.xml
│ │ │ └── uiDesigner.xml
│ │ ├── ch03_03.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── ExecutorDemoOne.java
│ │ │ ├── ExecutorDemoTwo.java
│ │ │ ├── ExecutorDemoThree.java
│ │ │ └── ExecutorDemoFour.java
│ ├── ch03_04
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── ch03_04.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── ScheduledExecutorServiceDemo1.java
│ │ │ ├── ScheduledExecutorServiceDemo2.java
│ │ │ └── ScheduledExecutorServiceDemo3.java
│ ├── ch03_05
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── vcs.xml
│ │ │ ├── misc.xml
│ │ │ └── modules.xml
│ │ ├── src
│ │ │ ├── Candidate.java
│ │ │ ├── NumberMagic.java
│ │ │ └── VotingSimulator.java
│ │ ├── ch03_05.iml
│ │ └── .gitignore
│ └── ch03_06
│ │ ├── ch03_06b
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── vcs.xml
│ │ │ ├── misc.xml
│ │ │ └── modules.xml
│ │ ├── src
│ │ │ ├── Candidate.java
│ │ │ ├── NumberMagic.java
│ │ │ └── VotingSimulator.java
│ │ ├── ch03_06b.iml
│ │ └── .gitignore
│ │ └── ch03_06e
│ │ ├── .idea
│ │ ├── .gitignore
│ │ ├── vcs.xml
│ │ ├── misc.xml
│ │ └── modules.xml
│ │ ├── src
│ │ ├── Candidate.java
│ │ ├── NumberMagic.java
│ │ └── VotingSimulator.java
│ │ ├── ch03_06e.iml
│ │ └── .gitignore
├── 01-Synchronization
│ ├── ch01_01
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── src
│ │ │ ├── MyRunnable.java
│ │ │ └── Main.java
│ │ ├── ch01_01.iml
│ │ └── .gitignore
│ ├── ch01_02
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── compiler.xml
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── src
│ │ │ ├── MyRunnable.java
│ │ │ └── Main.java
│ │ ├── ch01_02.iml
│ │ └── .gitignore
│ ├── ch01_03
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── ch01_03.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── Main.java
│ │ │ └── MyRunnable.java
│ ├── ch01_05
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── ch01_05.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── Main.java
│ │ │ └── MyRunnable.java
│ ├── ch01_06
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── vcs.xml
│ │ │ ├── misc.xml
│ │ │ └── modules.xml
│ │ ├── ch01_06.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── InventoryManager.java
│ │ │ └── Main.java
│ └── ch01_07
│ │ ├── ch01_07b
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── misc.xml
│ │ │ ├── vcs.xml
│ │ │ └── modules.xml
│ │ ├── ch01_07b.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── InventoryManager.java
│ │ │ └── Main.java
│ │ └── ch01_07e
│ │ ├── .idea
│ │ ├── .gitignore
│ │ ├── vcs.xml
│ │ ├── misc.xml
│ │ └── modules.xml
│ │ ├── ch01_07e.iml
│ │ ├── .gitignore
│ │ └── src
│ │ ├── Main.java
│ │ └── InventoryManager.java
├── 04-Fork-Join Framework
│ ├── ch04_04
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── ch04_04.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── RecursiveActionMain.java
│ │ │ ├── RecursiveTaskMain.java
│ │ │ ├── SumListAction.java
│ │ │ └── SumListTask.java
│ ├── ch04_05
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── vcs.xml
│ │ │ ├── misc.xml
│ │ │ └── modules.xml
│ │ ├── ch04_05.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── MultiplesCalculator.java
│ │ │ └── MultiplesCalculatorMain.java
│ └── ch04_06
│ │ ├── ch04_06b
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── misc.xml
│ │ │ ├── vcs.xml
│ │ │ └── modules.xml
│ │ ├── ch04_06b.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ ├── MultiplesCalculator.java
│ │ │ └── MultiplesCalculatorMain.java
│ │ └── ch04_06e
│ │ ├── .idea
│ │ ├── .gitignore
│ │ ├── vcs.xml
│ │ ├── misc.xml
│ │ └── modules.xml
│ │ ├── ch04_06e.iml
│ │ ├── .gitignore
│ │ └── src
│ │ ├── MultiplesCalculator.java
│ │ └── MultiplesCalculatorMain.java
├── 05-Concurrent Data Structures
│ ├── ch05_01
│ │ ├── .idea
│ │ │ ├── .gitignore
│ │ │ ├── modules.xml
│ │ │ ├── misc.xml
│ │ │ └── workspace.xml
│ │ ├── ch05_01.iml
│ │ ├── .gitignore
│ │ └── src
│ │ │ └── FailFastDemo.java
│ └── ch05_03
│ │ ├── .idea
│ │ ├── .gitignore
│ │ ├── modules.xml
│ │ ├── misc.xml
│ │ └── workspace.xml
│ │ ├── ch05_03.iml
│ │ ├── .gitignore
│ │ └── src
│ │ ├── CopyOnWriteArrayListCreateDemo.java
│ │ ├── FailFastDemo.java
│ │ ├── NonThreadSafeHashMapDemo.java
│ │ ├── CopyOnWriteArrayListUseDemo.java
│ │ ├── ConcurrentHashMapUseDemo.java
│ │ └── ConcurrentHashMapCreateDemo.java
└── 07-Virtual Threads in action
│ ├── ch07_01
│ ├── .idea
│ │ ├── .gitignore
│ │ ├── dictionaries
│ │ │ └── LI_Learning.xml
│ │ ├── compiler.xml
│ │ ├── modules.xml
│ │ ├── misc.xml
│ │ └── workspace.xml
│ ├── ch07_01.iml
│ ├── .gitignore
│ └── src
│ │ └── VirtualThreadDemo.java
│ └── ch07_02
│ ├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── workspace.xml
│ ├── ch07_02.iml
│ ├── .gitignore
│ └── src
│ ├── VirtualThreadPerformance1.java
│ └── VirtualThreadPerformance2.java
├── .github
├── CODEOWNERS
├── PULL_REQUEST_TEMPLATE.md
├── workflows
│ └── main.yml
└── ISSUE_TEMPLATE.md
├── .gitignore
├── CONTRIBUTING.md
├── NOTICE
├── README.md
└── LICENSE
/source/02-Asynchronous Programming/ch02_04/.idea/.name:
--------------------------------------------------------------------------------
1 | CompletableFutureDemo1.java
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Codeowners for these exercise files:
2 | # * (asterisk) denotes "all files and folders"
3 | # Example: * @producer @instructor
4 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.idea/dictionaries/LI_Learning.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/src/MyRunnable.java:
--------------------------------------------------------------------------------
1 | public class MyRunnable implements Runnable {
2 |
3 | @Override
4 | public void run() {
5 | for(int i = 0; i < 100; i++) {
6 | System.out.println(i);
7 | }
8 |
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/src/MyRunnable.java:
--------------------------------------------------------------------------------
1 | public class MyRunnable implements Runnable {
2 |
3 | private int counter;
4 |
5 | public int getCounter() {
6 | return counter;
7 | }
8 |
9 | @Override
10 | public void run() {
11 | for(int i = 0; i < 1_000_000; i++) {
12 | counter++;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Copy To Branches
2 | on:
3 | workflow_dispatch:
4 | jobs:
5 | copy-to-branches:
6 | runs-on: ubuntu-latest
7 | steps:
8 | - uses: actions/checkout@v2
9 | with:
10 | fetch-depth: 0
11 | - name: Copy To Branches Action
12 | uses: planetoftheweb/copy-to-branches@v1.2
13 | env:
14 | key: main
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 | replay_pid*
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/src/StepFourSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class StepFourSolution {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Write code for the Task 04 solution here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/src/StepTwoSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class StepTwoSolution {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Write code for the Task 02 solution here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/src/StepThreeSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class StepThreeSolution {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Write code for the Task 03 solution here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/src/OtherTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class OtherTask implements Callable {
5 | @Override
6 | public String call() throws Exception {
7 | System.out.println("Processing data...");
8 | TimeUnit.SECONDS.sleep(1);
9 | return "Data processing finished";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/src/StepFourSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class StepFourSolution {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Write code for the Task 04 solution here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/src/StepTwoSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class StepTwoSolution {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Write code for the Task 02 solution here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/src/StepThreeSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class StepThreeSolution {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Write code for the Task 03 solution here
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/src/TimeConsumingTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class TimeConsumingTask implements Callable {
5 | @Override
6 | public String call() throws Exception {
7 | System.out.println("Accessing data over the network...");
8 | TimeUnit.SECONDS.sleep(4);
9 | return "Accessing data finished";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/src/Candidate.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 |
4 | public class Candidate {
5 |
6 | private String name;
7 | private List votes = new ArrayList<>();
8 |
9 | public Candidate(String name) {
10 | this.name = name;
11 | }
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public List getVotes() {
18 | return votes;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/src/Candidate.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 |
4 | public class Candidate {
5 |
6 | private String name;
7 | private List votes = new ArrayList<>();
8 |
9 | public Candidate(String name) {
10 | this.name = name;
11 | }
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public List getVotes() {
18 | return votes;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/src/Candidate.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 |
4 | public class Candidate {
5 |
6 | private String name;
7 | private List votes = new ArrayList<>();
8 |
9 | public Candidate(String name) {
10 | this.name = name;
11 | }
12 |
13 | public String getName() {
14 | return name;
15 | }
16 |
17 | public List getVotes() {
18 | return votes;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/ch03_03.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/ch03_04.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/ch03_05.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/ch01_01.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/ch01_02.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/ch01_03.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/ch01_05.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/ch01_06.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/ch03_06b.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/ch03_06e.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/ch04_04.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/ch04_05.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/ch02_02.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/ch02_04.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/ch02_05.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/ch01_07b.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/ch01_07e.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/ch04_06b.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/ch04_06e.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/ch05_01.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/ch05_03.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/ch07_01.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/ch07_02.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/ch02_06b.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/ch02_06e.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/.gitignore:
--------------------------------------------------------------------------------
1 | ### IntelliJ IDEA ###
2 | out/
3 | !**/src/main/**/out/
4 | !**/src/test/**/out/
5 |
6 | ### Eclipse ###
7 | .apt_generated
8 | .classpath
9 | .factorypath
10 | .project
11 | .settings
12 | .springBeans
13 | .sts4-cache
14 | bin/
15 | !**/src/main/**/bin/
16 | !**/src/test/**/bin/
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /nbbuild/
21 | /dist/
22 | /nbdist/
23 | /.nb-gradle/
24 |
25 | ### VS Code ###
26 | .vscode/
27 |
28 | ### Mac OS ###
29 | .DS_Store
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/src/ExecutorDemoOne.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 |
3 | public class ExecutorDemoOne {
4 |
5 | public static void main(String[] args) {
6 |
7 | ExecutorService executorService = Executors.newSingleThreadExecutor();
8 |
9 | executorService.execute(new Runnable() {
10 | public void run() {
11 | String threadName = Thread.currentThread().getName();
12 | System.out.println(threadName + " executing the task");
13 | }
14 | });
15 |
16 | executorService.shutdown();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 |
3 | public static void main(String[] args) {
4 |
5 | MyRunnable myRunnable = new MyRunnable();
6 | Thread thread1 = new Thread(myRunnable, "Thread1");
7 | Thread thread2 = new Thread(myRunnable, "Thread2");
8 |
9 | thread1.start();
10 | thread2.start();
11 |
12 | try {
13 | Thread.sleep(1000);
14 | } catch (InterruptedException e) {
15 | throw new RuntimeException(e);
16 | }
17 |
18 | System.out.println(myRunnable.getCounter());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 |
3 | public static void main(String[] args) {
4 |
5 | MyRunnable myRunnable = new MyRunnable();
6 | Thread thread1 = new Thread(myRunnable, "Thread1");
7 | Thread thread2 = new Thread(myRunnable, "Thread2");
8 |
9 | thread1.start();
10 | thread2.start();
11 |
12 | try {
13 | Thread.sleep(1000);
14 | } catch (InterruptedException e) {
15 | throw new RuntimeException(e);
16 | }
17 |
18 | System.out.println("Final value of counter is: " + myRunnable.getCounter());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 |
3 | public static void main(String[] args) {
4 |
5 | MyRunnable myRunnable = new MyRunnable();
6 | Thread thread1 = new Thread(myRunnable, "Thread1");
7 | Thread thread2 = new Thread(myRunnable, "Thread2");
8 |
9 | thread1.start();
10 | thread2.start();
11 |
12 | try {
13 | Thread.sleep(1000);
14 | } catch (InterruptedException e) {
15 | throw new RuntimeException(e);
16 | }
17 |
18 | System.out.println("Final value of counter is: " + myRunnable.getCounter());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | Contribution Agreement
3 | ======================
4 |
5 | This repository does not accept pull requests (PRs). All pull requests will be closed.
6 |
7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license.
8 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/src/SumOfSquaresTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class SumOfSquaresTask implements Callable {
5 | @Override
6 | public Integer call() throws Exception {
7 | System.out.println("Calculating the sum of squares ...");
8 | int sum = 0;
9 | for(int i = 0; i < 10; i++) {
10 | int square = i * i;
11 | sum += square;
12 | TimeUnit.SECONDS.sleep(1);
13 | }
14 | System.out.println("Finished calculating the sum of squares");
15 | return sum;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Copyright 2024 LinkedIn Corporation
2 | All Rights Reserved.
3 |
4 | Licensed under the LinkedIn Learning Exercise File License (the "License").
5 | See LICENSE in the project root for license information.
6 |
7 | Please note, this project may automatically load third party code from external
8 | repositories (for example, NPM modules, Composer packages, or other dependencies).
9 | If so, such third party code may be subject to other license terms than as set
10 | forth above. In addition, such third party code may also depend on and load
11 | multiple tiers of dependencies. Please review the applicable licenses of the
12 | additional dependencies.
13 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/src/StepOneSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 |
3 | public class StepOneSolution {
4 | public static void main(String[] args) throws InterruptedException, ExecutionException {
5 | // Write code for the Task 01 solution here
6 |
7 | long startTime = System.nanoTime();
8 |
9 | // Place your solution code here
10 |
11 | long elapsedTime = System.nanoTime() - startTime;
12 | System.out.println("Both tasks finished in " + (elapsedTime/1000000)/1000 + " seconds");
13 |
14 | // Don't forget to shut down the executor service once you are done
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/src/StepOneSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 |
3 | public class StepOneSolution {
4 | public static void main(String[] args) throws InterruptedException, ExecutionException {
5 | // Write code for the Task 01 solution here
6 |
7 | long startTime = System.nanoTime();
8 |
9 | // Place your solution code here
10 |
11 | long elapsedTime = System.nanoTime() - startTime;
12 | System.out.println("Both tasks finished in " + (elapsedTime/1000000)/1000 + " seconds");
13 |
14 | // Don't forget to shut down the executor service once you are done
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/src/SumOfSquaresTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class SumOfSquaresTask implements Callable {
5 | @Override
6 | public Integer call() throws Exception {
7 | System.out.println("Calculating the sum of squares ...");
8 | int sum = 0;
9 | for(int i = 0; i < 10; i++) {
10 | int square = i * i;
11 | sum += square;
12 | TimeUnit.SECONDS.sleep(1);
13 | }
14 | System.out.println("Finished calculating the sum of squares");
15 | return sum;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/src/SumOfSquaresTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class SumOfSquaresTask implements Callable {
5 | @Override
6 | public Integer call() throws Exception {
7 | System.out.println("Calculating the sum of squares ...");
8 | int sum = 0;
9 | for(int i = 0; i < 10; i++) {
10 | int square = i * i;
11 | sum += square;
12 | TimeUnit.SECONDS.sleep(1);
13 | }
14 | System.out.println("Finished calculating the sum of squares");
15 | return sum;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/src/MyRunnable.java:
--------------------------------------------------------------------------------
1 | public class MyRunnable implements Runnable {
2 |
3 | private int counter;
4 |
5 | public int getCounter() {
6 | return counter;
7 | }
8 |
9 | @Override
10 | public void run() {
11 |
12 | long startTime = System.nanoTime();
13 | for(int i = 0; i < 1_000_000; i++) {
14 | counter++;
15 | }
16 | long elapsedTime = System.nanoTime() - startTime;
17 |
18 | System.out.println(Thread.currentThread().getName() + " increased the counter up to: " +
19 | counter + " in " + elapsedTime/1000000 + " milliseconds");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_05/src/SumOfEvenTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class SumOfEvenTask implements Callable {
5 | @Override
6 | public Integer call() throws Exception {
7 | System.out.println("Calculating the sum of even numbers ...");
8 | int sum = 0;
9 | for(int i = 0; i < 10; i++) {
10 | if(i%2 == 0) {
11 | sum += i;
12 | }
13 | TimeUnit.SECONDS.sleep(2);
14 | }
15 | System.out.println("Finished calculating the sum of even numbers");
16 | return sum;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/src/InventoryManager.java:
--------------------------------------------------------------------------------
1 | public class InventoryManager implements Runnable {
2 | private int itemCount = 200000;
3 | public int getItemCount() {
4 | return itemCount;
5 | }
6 |
7 | @Override
8 | public void run() {
9 | String function = Thread.currentThread().getName();
10 |
11 | if(function.equals("issue")) {
12 | for(int i = 0; i < 100000; i++) {
13 | itemCount--;
14 | }
15 | } else if(function.equals("receive")) {
16 | for(int i = 0; i < 100000; i++) {
17 | itemCount++;
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/src/RecursiveActionMain.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.Random;
3 | import java.util.concurrent.ForkJoinPool;
4 |
5 | import static java.util.stream.Collectors.toList;
6 |
7 | public class RecursiveActionMain {
8 |
9 | public static void main(String[] args) {
10 |
11 | Random random = new Random();
12 | List data = random
13 | .longs(11, 1, 5)
14 | .boxed()
15 | .collect(toList());
16 |
17 | ForkJoinPool pool = new ForkJoinPool();
18 | SumListAction task = new SumListAction(data);
19 | pool.invoke(task);
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06b/src/SumOfEvenTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class SumOfEvenTask implements Callable {
5 | @Override
6 | public Integer call() throws Exception {
7 | System.out.println("Calculating the sum of even numbers ...");
8 | int sum = 0;
9 | for(int i = 0; i < 10; i++) {
10 | if(i%2 == 0) {
11 | sum += i;
12 | }
13 | TimeUnit.SECONDS.sleep(2);
14 | }
15 | System.out.println("Finished calculating the sum of even numbers");
16 | return sum;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/src/SumOfEvenTask.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.Callable;
2 | import java.util.concurrent.TimeUnit;
3 |
4 | public class SumOfEvenTask implements Callable {
5 | @Override
6 | public Integer call() throws Exception {
7 | System.out.println("Calculating the sum of even numbers ...");
8 | int sum = 0;
9 | for(int i = 0; i < 10; i++) {
10 | if(i%2 == 0) {
11 | sum += i;
12 | }
13 | TimeUnit.SECONDS.sleep(2);
14 | }
15 | System.out.println("Finished calculating the sum of even numbers");
16 | return sum;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_06/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 | public static void main(String[] args) {
3 |
4 | InventoryManager inventoryManager = new InventoryManager();
5 | Thread issuer = new Thread(inventoryManager, "issue");
6 | Thread receiver = new Thread(inventoryManager, "receive");
7 |
8 | issuer.start();
9 | receiver.start();
10 |
11 | try {
12 | Thread.sleep(1000);
13 | } catch (InterruptedException e) {
14 | throw new RuntimeException(e);
15 | }
16 |
17 | System.out.println("Current number of items in inventory: " + inventoryManager.getItemCount());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/src/InventoryManager.java:
--------------------------------------------------------------------------------
1 | public class InventoryManager implements Runnable {
2 | private int itemCount = 200000;
3 | public int getItemCount() {
4 | return itemCount;
5 | }
6 |
7 | @Override
8 | public void run() {
9 | String function = Thread.currentThread().getName();
10 |
11 | if(function.equals("issue")) {
12 | for(int i = 0; i < 100000; i++) {
13 | itemCount--;
14 | }
15 | } else if(function.equals("receive")) {
16 | for(int i = 0; i < 100000; i++) {
17 | itemCount++;
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07b/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 | public static void main(String[] args) {
3 |
4 | InventoryManager inventoryManager = new InventoryManager();
5 | Thread issuer = new Thread(inventoryManager, "issue");
6 | Thread receiver = new Thread(inventoryManager, "receive");
7 |
8 | issuer.start();
9 | receiver.start();
10 |
11 | try {
12 | Thread.sleep(1000);
13 | } catch (InterruptedException e) {
14 | throw new RuntimeException(e);
15 | }
16 |
17 | System.out.println("Current number of items in inventory: " + inventoryManager.getItemCount());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 | public static void main(String[] args) {
3 |
4 | InventoryManager inventoryManager = new InventoryManager();
5 | Thread issuer = new Thread(inventoryManager, "issue");
6 | Thread receiver = new Thread(inventoryManager, "receive");
7 |
8 | issuer.start();
9 | receiver.start();
10 |
11 | try {
12 | Thread.sleep(1000);
13 | } catch (InterruptedException e) {
14 | throw new RuntimeException(e);
15 | }
16 |
17 | System.out.println("Current number of items in inventory: " + inventoryManager.getItemCount());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/src/RecursiveTaskMain.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.Random;
3 | import java.util.concurrent.ForkJoinPool;
4 | import java.util.concurrent.RecursiveTask;
5 |
6 | import static java.util.stream.Collectors.toList;
7 |
8 | public class RecursiveTaskMain {
9 | public static void main(String[] args) {
10 | Random random = new Random();
11 | List data = random
12 | .longs(10, 1, 5)
13 | .boxed()
14 | .collect(toList());
15 |
16 | ForkJoinPool pool = new ForkJoinPool();
17 | SumListTask task = new SumListTask(data);
18 | System.out.println("Sum: " + pool.invoke(task));
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/src/ScheduledExecutorServiceDemo1.java:
--------------------------------------------------------------------------------
1 | import java.time.LocalDateTime;
2 | import java.util.concurrent.*;
3 |
4 | public class ScheduledExecutorServiceDemo1 {
5 | public static void main(String[] args) throws ExecutionException, InterruptedException {
6 | ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
7 |
8 | Runnable task = () -> {
9 | System.out.println("Executing Task 1 at " + LocalDateTime.now());
10 | };
11 |
12 | ScheduledFuture> future = scheduledExecutorService.schedule(task, 5, TimeUnit.SECONDS);
13 |
14 | System.out.println(future.get());
15 |
16 | scheduledExecutorService.shutdown();
17 |
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/src/Main.java:
--------------------------------------------------------------------------------
1 | public class Main {
2 |
3 | public static void main(String[] args) {
4 |
5 | // Step 1
6 | // MyRunnable myRunnable1 = new MyRunnable();
7 | // Thread thread1 = new Thread(myRunnable1, "Thread1");
8 | //
9 | // MyRunnable myRunnable2 = new MyRunnable();
10 | // Thread thread2 = new Thread(myRunnable2, "Thread2");
11 | //
12 | // thread1.start();
13 | // thread2.start();
14 |
15 | // Step 2
16 | MyRunnable myRunnable = new MyRunnable();
17 | Thread thread1 = new Thread(myRunnable, "Thread1");
18 | Thread thread2 = new Thread(myRunnable, "Thread2");
19 |
20 | thread1.start();
21 | thread2.start();
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/src/MultiplesCalculator.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 |
3 | public class MultiplesCalculator {
4 | private List numbers;
5 | public static int threshold;
6 | public static int multipleOf;
7 |
8 | public MultiplesCalculator(List numbers) {
9 | this.numbers = numbers;
10 | }
11 |
12 | /* Override the compute() method with the implementation for calculating multiples here
13 | i.e. divide and conquer mechanism based on the threshold value
14 | */
15 |
16 | protected int computeDirectly() {
17 | int count = 0;
18 | for (Integer n: numbers) {
19 | if (n % multipleOf == 0) {
20 | count +=1;
21 | }
22 | }
23 | return count;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_07/ch01_07e/src/InventoryManager.java:
--------------------------------------------------------------------------------
1 | public class InventoryManager implements Runnable {
2 | private int itemCount = 200000;
3 | public int getItemCount() {
4 | return itemCount;
5 | }
6 |
7 | @Override
8 | public void run() {
9 | String function = Thread.currentThread().getName();
10 |
11 | if(function.equals("issue")) {
12 | for(int i = 0; i < 100000; i++) {
13 | synchronized (this) {
14 | itemCount--;
15 | }
16 | }
17 | } else if(function.equals("receive")) {
18 | for(int i = 0; i < 100000; i++) {
19 | synchronized (this) {
20 | itemCount++;
21 | }
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/src/MultiplesCalculator.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 |
3 | public class MultiplesCalculator {
4 | private List numbers;
5 | public static int threshold;
6 | public static int multipleOf;
7 |
8 | public MultiplesCalculator(List numbers) {
9 | this.numbers = numbers;
10 | }
11 |
12 | /* Override the compute() method with the implementation for calculating multiples here
13 | i.e. divide and conquer mechanism based on the threshold value
14 | */
15 |
16 | protected int computeDirectly() {
17 | int count = 0;
18 | for (Integer n: numbers) {
19 | if (n % multipleOf == 0) {
20 | count +=1;
21 | }
22 | }
23 | return count;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/src/MyRunnable.java:
--------------------------------------------------------------------------------
1 | public class MyRunnable implements Runnable {
2 |
3 | private int counter;
4 |
5 | public int getCounter() {
6 | return counter;
7 | }
8 |
9 | @Override
10 | public void run() {
11 |
12 | long startTime = System.nanoTime();
13 | for(int i = 0; i < 1_000_000; i++) {
14 | synchronized (this) {
15 | counter++;
16 | }
17 | }
18 | long elapsedTime = System.nanoTime() - startTime;
19 |
20 | System.out.println(Thread.currentThread().getName() + " increased the counter up to: " +
21 | counter + " in " + elapsedTime/1000000 + " milliseconds");
22 | }
23 |
24 | public synchronized void someMethod() {
25 | // Critical section here
26 | // The monitor is implicitly the monitor of the current object to which the method belongs
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/src/VirtualThreadPerformance1.java:
--------------------------------------------------------------------------------
1 | public class VirtualThreadPerformance1 {
2 |
3 | public static void main(String[] args) throws InterruptedException {
4 |
5 | // long startTime = System.nanoTime();
6 | //
7 | // for(int i = 0; i < 1_000_000; i++) {
8 | // Thread.ofPlatform().start(() -> System.out.println(Thread.currentThread()));
9 | // }
10 | //
11 | // long elapsedTime = System.nanoTime() - startTime;
12 | // System.out.println((elapsedTime/1000000) / 1000 + " seconds");
13 |
14 | long startTime = System.nanoTime();
15 |
16 | for(int i = 0; i < 1_000_000; i++) {
17 | Thread thread = Thread.ofVirtual().start(() -> System.out.println(Thread.currentThread()));
18 | thread.join();
19 | }
20 |
21 | long elapsedTime = System.nanoTime() - startTime;
22 | System.out.println((elapsedTime/1000000)/ 1000 + " seconds");
23 |
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/src/ScheduledExecutorServiceDemo2.java:
--------------------------------------------------------------------------------
1 | import java.time.LocalDateTime;
2 | import java.util.concurrent.*;
3 |
4 | public class ScheduledExecutorServiceDemo2 {
5 | private static int count = 0;
6 |
7 | public static void main(String[] args) throws InterruptedException {
8 |
9 | ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
10 |
11 | Runnable task1 = () -> {
12 | count++;
13 | System.out.println("Counting " + count + " at " + LocalDateTime.now());
14 | };
15 |
16 | ScheduledFuture> scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(task1, 5, 1, TimeUnit.SECONDS);
17 |
18 | while (count != 5) {
19 | TimeUnit.MILLISECONDS.sleep(100);
20 | }
21 |
22 | System.out.println("Count is 5, cancel the scheduledFuture!");
23 | scheduledFuture.cancel(true);
24 | scheduledExecutorService.shutdown();
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/src/Main.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 |
3 | public class Main {
4 | public static void main(String[] args) throws InterruptedException, ExecutionException {
5 | ExecutorService executorService = Executors.newFixedThreadPool(2);
6 |
7 | long startTime = System.nanoTime();
8 | Future future1 = executorService.submit(new TimeConsumingTask());
9 | Future future2 = executorService.submit(new OtherTask());
10 |
11 | while (!future1.isDone() && !future2.isDone()) {
12 | System.out.println("Reading and processing not yet finished.");
13 | // Simulating another task
14 | TimeUnit.SECONDS.sleep(1);
15 | }
16 |
17 | System.out.println(future1.get());
18 | System.out.println(future2.get());
19 |
20 | long elapsedTime = System.nanoTime() - startTime;
21 | System.out.println("Both tasks finished in " + (elapsedTime/1000000)/1000 + " seconds");
22 |
23 | executorService.shutdown();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/src/StepOneSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 |
3 | public class StepOneSolution {
4 | public static void main(String[] args) throws InterruptedException, ExecutionException {
5 |
6 | // Task 01
7 | ExecutorService executorService = Executors.newFixedThreadPool(2);
8 |
9 | long startTime = System.nanoTime();
10 | Future future1 = executorService.submit(new SumOfEvenTask());
11 | Future future2 = executorService.submit(new SumOfSquaresTask());
12 |
13 | while (!future1.isDone() && !future2.isDone()) {
14 | System.out.println("Tasks are in progress..");
15 | }
16 |
17 | System.out.println("Sum of Even Numbers: " + future1.get());
18 | System.out.println("Sum of Squares: " + future2.get());
19 |
20 | long elapsedTime = System.nanoTime() - startTime;
21 | System.out.println("Both tasks finished in " + (elapsedTime/1000000)/1000 + " seconds");
22 |
23 | executorService.shutdown();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/src/SumListAction.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.concurrent.RecursiveAction;
3 |
4 | public class SumListAction extends RecursiveAction {
5 | private List numbers;
6 | private static final int THRESHOLD = 5;
7 |
8 | public SumListAction(List numbers) {
9 | this.numbers = numbers;
10 | }
11 |
12 | @Override
13 | protected void compute() {
14 | if(numbers.size() <= THRESHOLD) {
15 | long sum = computeDirectly();
16 | System.out.format("Sum of %s: %d\n", numbers.toString(), sum);
17 | } else {
18 | int mid = numbers.size() / 2;
19 | SumListAction subTask1 = new SumListAction(numbers.subList(0, mid));
20 | SumListAction subTask2 = new SumListAction(numbers.subList(mid, numbers.size()));
21 |
22 | invokeAll(subTask1, subTask2);
23 | }
24 | }
25 |
26 | protected long computeDirectly() {
27 | long sum = 0;
28 | for (Long n: numbers) {
29 | sum += n;
30 | }
31 | return sum;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/src/StepTwoSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 |
4 | public class StepTwoSolution {
5 | public static void main(String[] args) throws ExecutionException, InterruptedException {
6 |
7 | // Task 02
8 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
9 | System.out.println("Calculating the sum of even numbers ...");
10 | int sum = 0;
11 | for(int i = 0; i < 10; i++) {
12 | if(i%2 == 0) {
13 | sum += i;
14 | }
15 | }
16 | System.out.println("Finished calculating the sum of even numbers");
17 | return sum;
18 | });
19 |
20 | CompletableFuture futureWithCallback = future.thenApply(result -> {
21 | String inBinary = Integer.toBinaryString(result);
22 | return inBinary;
23 | });
24 |
25 | System.out.println("Sum of even numbers in binary: " + futureWithCallback.get());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/src/StepThreeSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 |
4 | public class StepThreeSolution {
5 | public static void main(String[] args) throws ExecutionException, InterruptedException {
6 | // Task 03
7 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
8 | System.out.println("Calculating the sum of even numbers ...");
9 | int sum = 0;
10 | for(int i = 0; i < 10; i++) {
11 | if(i%2 == 0) {
12 | sum += i;
13 | }
14 | }
15 | System.out.println("Finished calculating the sum of even numbers");
16 | return sum;
17 | }).thenCompose(result ->CompletableFuture.supplyAsync(() -> {
18 | // Calculating the square of the sum of even numbers
19 | return result * result;
20 | }
21 | ));
22 |
23 |
24 | System.out.println("Sum of even numbers squared: " + future.get());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/src/ScheduledExecutorServiceDemo3.java:
--------------------------------------------------------------------------------
1 | import java.time.LocalDateTime;
2 | import java.util.concurrent.Executors;
3 | import java.util.concurrent.ScheduledExecutorService;
4 | import java.util.concurrent.ScheduledFuture;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | public class ScheduledExecutorServiceDemo3 {
8 | private static int count = 0;
9 |
10 | public static void main(String[] args) throws InterruptedException {
11 |
12 | ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
13 |
14 | Runnable task1 = () -> {
15 | count++;
16 | System.out.println("Counting " + count + " at " + LocalDateTime.now());
17 | };
18 |
19 | ScheduledFuture> scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(task1, 5, 3, TimeUnit.SECONDS);
20 |
21 | while (count != 5) {
22 | TimeUnit.MILLISECONDS.sleep(100);
23 | }
24 |
25 | System.out.println("Count is 5, cancel the scheduledFuture!");
26 | scheduledFuture.cancel(true);
27 | scheduledExecutorService.shutdown();
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
7 |
8 | ## Issue Overview
9 |
10 |
11 | ## Describe your environment
12 |
13 |
14 | ## Steps to Reproduce
15 |
16 | 1.
17 | 2.
18 | 3.
19 | 4.
20 |
21 | ## Expected Behavior
22 |
23 |
24 | ## Current Behavior
25 |
26 |
27 | ## Possible Solution
28 |
29 |
30 | ## Screenshots / Video
31 |
32 |
33 | ## Related Issues
34 |
35 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/src/SumListTask.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.concurrent.RecursiveTask;
3 |
4 | public class SumListTask extends RecursiveTask {
5 | private List numbers;
6 | private static final int THRESHOLD = 5;
7 |
8 | public SumListTask(List numbers) {
9 | this.numbers = numbers;
10 | }
11 |
12 | @Override
13 | protected Long compute() {
14 | if(numbers.size() <= THRESHOLD) {
15 | long sum = computeDirectly();
16 | System.out.format("Sum of %s: %d\n", numbers.toString(), sum);
17 | return sum;
18 | } else {
19 | int mid = numbers.size() / 2;
20 | SumListTask subTask1 = new SumListTask(numbers.subList(0, mid));
21 | SumListTask subTask2 = new SumListTask(numbers.subList(mid, numbers.size()));
22 |
23 | invokeAll(subTask1, subTask2);
24 |
25 | return subTask1.join() + subTask2.join();
26 | }
27 | }
28 |
29 | protected long computeDirectly() {
30 | long sum = 0;
31 | for (Long n: numbers) {
32 | sum += n;
33 | }
34 | return sum;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/src/NumberMagic.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.concurrent.*;
3 |
4 |
5 | public class NumberMagic {
6 | static int number = 0;
7 | public static void main(String[] args) throws InterruptedException, ExecutionException {
8 | Scanner myObj = new Scanner(System.in);
9 | boolean flag;
10 |
11 | do {
12 | System.out.print("Enter an integer number: ");
13 | try {
14 | number = Integer.parseInt(myObj.nextLine());
15 | flag = false;
16 | } catch (NumberFormatException e) {
17 | System.out.println("Not a valid integer");
18 | flag = true;
19 | }
20 | } while(flag);
21 |
22 | /* Write code here to create the 3 tasks:
23 | 1. calculating the square root
24 | 2. calculating the factorial, of the given number
25 | 3.represent the number in binary form
26 | and execute them using an executor service
27 | Hint: you've seen 4 task execution methods during demos.
28 | Decide which task execution method is suitable in this case. */
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/src/NumberMagic.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.concurrent.*;
3 |
4 |
5 | public class NumberMagic {
6 | static int number = 0;
7 | public static void main(String[] args) throws InterruptedException, ExecutionException {
8 | Scanner myObj = new Scanner(System.in);
9 | boolean flag;
10 |
11 | do {
12 | System.out.print("Enter an integer number: ");
13 | try {
14 | number = Integer.parseInt(myObj.nextLine());
15 | flag = false;
16 | } catch (NumberFormatException e) {
17 | System.out.println("Not a valid integer");
18 | flag = true;
19 | }
20 | } while(flag);
21 |
22 | /* Write code here to create the 3 tasks:
23 | 1. calculating the square root
24 | 2. calculating the factorial, of the given number
25 | 3.represent the number in binary form
26 | and execute them using an executor service
27 | Hint: you've seen 4 task execution methods during demos.
28 | Decide which task execution method is suitable in this case. */
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/src/CopyOnWriteArrayListCreateDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 | import java.util.Iterator;
3 | import java.util.List;
4 | import java.util.concurrent.CopyOnWriteArrayList;
5 |
6 | public class CopyOnWriteArrayListCreateDemo {
7 | public static void main(String[] args) {
8 | List list = Arrays.asList("Sam", "John", "Bob");
9 | CopyOnWriteArrayList copyOnWriteList = new CopyOnWriteArrayList<>(list);
10 |
11 | System.out.println("Before modifying: " + copyOnWriteList);
12 |
13 | Iterator iterator1 = copyOnWriteList.iterator();
14 |
15 | // Modify list
16 | copyOnWriteList.add("Pat");
17 | System.out.println("After modifying: " + copyOnWriteList);
18 |
19 | Iterator iterator2 = copyOnWriteList.iterator();
20 |
21 | System.out.println("Elements from Iterator1 :");
22 | while (iterator1.hasNext()) {
23 | System.out.println(iterator1.next());
24 | }
25 |
26 | System.out.println("Elements from Iterator2 :");
27 | while (iterator2.hasNext()) {
28 | System.out.println(iterator2.next());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/src/FailFastDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.ListIterator;
4 |
5 | public class FailFastDemo {
6 | private List list = new ArrayList<>();
7 |
8 | public FailFastDemo() {
9 | for (int i = 0; i < 1000; i++) {
10 | list.add(i);
11 | }
12 | }
13 |
14 | public void iterateList() {
15 | Thread thread1 = new Thread(()-> {
16 | ListIterator iterator = list.listIterator();
17 | while (iterator.hasNext()) {
18 | Integer number = iterator.next();
19 | System.out.println(number);
20 | }
21 | });
22 |
23 | thread1.start();
24 | }
25 |
26 | public void modifyList() {
27 | Thread thread2 = new Thread(()-> {
28 | for (int i = 1000; i < 2000; i++) {
29 | list.add(i);
30 | }
31 | });
32 |
33 | thread2.start();
34 | }
35 |
36 | public static void main(String[] args) {
37 | FailFastDemo demo = new FailFastDemo();
38 |
39 | demo.iterateList();
40 | demo.modifyList();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/src/FailFastDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.ListIterator;
4 |
5 | public class FailFastDemo {
6 | private List list = new ArrayList<>();
7 |
8 | public FailFastDemo() {
9 | list.add("Sam");
10 | list.add("John");
11 | list.add("Bob");
12 | list.add("Pat");
13 | }
14 |
15 | public void iterateList() {
16 | Thread thread1 = new Thread(()-> {
17 | ListIterator iterator = list.listIterator();
18 | while (iterator.hasNext()) {
19 | System.out.println(iterator.next());
20 | }
21 | });
22 |
23 | thread1.start();
24 | }
25 |
26 | public void modifyList() {
27 | Thread thread2 = new Thread(()-> {
28 | for(int i = 0; i < list.size(); i++) {
29 | if(i == 2)
30 | list.remove(i);
31 | }
32 | });
33 |
34 | thread2.start();
35 | }
36 |
37 | public static void main(String[] args) {
38 | FailFastDemo demo = new FailFastDemo();
39 |
40 | demo.iterateList();
41 | demo.modifyList();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/src/ExecutorDemoTwo.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 |
3 | public class ExecutorDemoTwo {
4 |
5 | public static void main(String[] args) throws ExecutionException, InterruptedException {
6 |
7 | ExecutorService executorService = Executors.newFixedThreadPool(3);
8 |
9 | Callable task1 = () -> {
10 | String threadName = Thread.currentThread().getName();
11 | return threadName + " executing Task 1";
12 | };
13 |
14 | Callable task2 = () -> {
15 | String threadName = Thread.currentThread().getName();
16 | return threadName + " executing Task 2";
17 | };
18 |
19 | Callable task3 = () -> {
20 | String threadName = Thread.currentThread().getName();
21 | return threadName + " executing Task 3";
22 | };
23 |
24 | Future future1 = executorService.submit(task1);
25 | Future future2 = executorService.submit(task2);
26 | Future future3 = executorService.submit(task3);
27 |
28 | System.out.println(future1.get());
29 | System.out.println(future2.get());
30 | System.out.println(future3.get());
31 |
32 | executorService.shutdown();
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/src/ExecutorDemoThree.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.concurrent.*;
4 |
5 | public class ExecutorDemoThree {
6 |
7 | public static void main(String[] args) throws ExecutionException, InterruptedException {
8 |
9 | ExecutorService executorService = Executors.newFixedThreadPool(3);
10 |
11 | Callable task1 = () -> {
12 | String threadName = Thread.currentThread().getName();
13 | return threadName + " executing Task 1";
14 | };
15 |
16 | Callable task2 = () -> {
17 | String threadName = Thread.currentThread().getName();
18 | return threadName + " executing Task 2";
19 | };
20 |
21 | Callable task3 = () -> {
22 | String threadName = Thread.currentThread().getName();
23 | return threadName + " executing Task 3";
24 | };
25 |
26 | List> callableTasks = new ArrayList<>();
27 | callableTasks.add(task1);
28 | callableTasks.add(task2);
29 | callableTasks.add(task3);
30 |
31 | String result = executorService.invokeAny(callableTasks);
32 |
33 | System.out.println(result);
34 |
35 | executorService.shutdown();
36 |
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/src/CompletableFutureDemo5.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class CompletableFutureDemo5 {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | String customerCode = "";
8 |
9 | // Retrieve number of points from a remote database call
10 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
11 | if(customerCode.isEmpty()) {
12 | throw new IllegalArgumentException("Customer code can not be empty");
13 | } else {
14 | System.out.println("Accessing customer loyalty points data over the network...");
15 | try {
16 | TimeUnit.SECONDS.sleep(4);
17 | } catch (InterruptedException e) {
18 | throw new RuntimeException(e);
19 | }
20 | return 200;
21 | }
22 | }).exceptionally(ex -> {
23 | System.out.println("There was an exception - " + ex.getMessage());
24 | return -1;
25 | });
26 |
27 |
28 | System.out.println("Total points " + future.get());
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/src/VirtualThreadPerformance2.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.ExecutorService;
2 | import java.util.concurrent.Executors;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class VirtualThreadPerformance2 {
6 | public static void main(String[] args) throws InterruptedException {
7 |
8 | Runnable blockingTask = () -> {
9 | try {
10 | TimeUnit.SECONDS.sleep(1);
11 | } catch (InterruptedException e) {
12 | throw new RuntimeException(e);
13 | }
14 | System.out.println("This is a blocking task");
15 | };
16 |
17 | long startTime = System.nanoTime();
18 |
19 | // try (ExecutorService executor = Executors.newFixedThreadPool(100)) {
20 | // for(int i = 0; i < 10_000; i++) {
21 | // executor.submit(blockingTask);
22 | // }
23 | // }
24 |
25 | try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
26 | for(int i = 0; i < 10_000; i++) {
27 | executor.submit(blockingTask);
28 | }
29 | }
30 |
31 | long elapsedTime = System.nanoTime() - startTime;
32 | System.out.println("Total elapsed time : " + (elapsedTime/1000000)/1000 + " seconds");
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_06/ch02_06e/src/StepFourSolution.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 |
4 | public class StepFourSolution {
5 | public static void main(String[] args) throws ExecutionException, InterruptedException {
6 | // Step 04
7 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
8 | System.out.println("Calculating the sum of even numbers ...");
9 | int sum = 0;
10 | for(int i = 0; i < 10; i++) {
11 | if(i%2 == 0) {
12 | sum += i;
13 | }
14 | }
15 | System.out.println("Finished calculating the sum of even numbers");
16 | return sum;
17 | }).thenCombine(CompletableFuture.supplyAsync(() -> {
18 | System.out.println("Calculating the sum of squares ...");
19 | int sum = 0;
20 | for(int i = 0; i < 10; i++) {
21 | int square = i * i;
22 | sum += square;
23 | }
24 | System.out.println("Finished calculating the sum of squares");
25 | return sum;
26 | }),(res1, res2) -> res1 + res2);
27 |
28 | System.out.println("Sum of even numbers + Sum of squares = " + future.get());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/src/NonThreadSafeHashMapDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.HashMap;
2 | import java.util.Iterator;
3 |
4 | public class NonThreadSafeHashMapDemo {
5 | HashMap productMap = new HashMap<>();
6 |
7 | public NonThreadSafeHashMapDemo() {
8 | productMap.put(100,"TV");
9 | productMap.put(101,"Laptop");
10 | productMap.put(102,"Blender");
11 | productMap.put(103,"Cooker");
12 | }
13 |
14 | public void iterateMap() {
15 | Thread thread1 = new Thread(()-> {
16 | Iterator iterator = productMap.keySet().iterator();
17 | while (iterator.hasNext()) {
18 | System.out.println(productMap.get(iterator.next()));
19 | }
20 | });
21 |
22 | thread1.start();
23 | System.out.println();
24 | }
25 |
26 | public void modifyMap() {
27 | Thread thread2 = new Thread(()-> {
28 | for(int key : productMap.keySet()) {
29 | if(key == 102)
30 | productMap.remove(key);
31 | }
32 | });
33 |
34 | thread2.start();
35 | }
36 |
37 |
38 | public static void main(String[] args) {
39 | NonThreadSafeHashMapDemo demo = new NonThreadSafeHashMapDemo();
40 | demo.iterateMap();
41 | demo.modifyMap();
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/src/ExecutorDemoFour.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.concurrent.*;
4 |
5 | public class ExecutorDemoFour {
6 |
7 | public static void main(String[] args) throws InterruptedException, ExecutionException {
8 |
9 | ExecutorService executorService = Executors.newFixedThreadPool(3);
10 |
11 | Callable task1 = () -> {
12 | String threadName = Thread.currentThread().getName();
13 | return threadName + " executing Task 1";
14 | };
15 |
16 | Callable task2 = () -> {
17 | String threadName = Thread.currentThread().getName();
18 | return threadName + " executing Task 2";
19 | };
20 |
21 | Callable task3 = () -> {
22 | String threadName = Thread.currentThread().getName();
23 | return threadName + " executing Task 3";
24 | };
25 |
26 | List> callableTasks = new ArrayList<>();
27 | callableTasks.add(task1);
28 | callableTasks.add(task2);
29 | callableTasks.add(task3);
30 |
31 | List> futures = executorService.invokeAll(callableTasks);
32 |
33 |
34 | for(Future future:futures) {
35 | System.out.println(future.get());
36 | }
37 |
38 | executorService.shutdown();
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/src/CompletableFutureDemo4.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class CompletableFutureDemo4 {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | String customerCode = "";
8 |
9 | // Retrieve number of points from a remote database call
10 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
11 | if (customerCode.isEmpty()) {
12 | throw new IllegalArgumentException("Customer code can not be empty");
13 | } else {
14 | System.out.println("Accessing customer loyalty points data over the network...");
15 | try {
16 | TimeUnit.SECONDS.sleep(4);
17 | } catch (InterruptedException e) {
18 | throw new RuntimeException(e);
19 | }
20 | return 200;
21 | }
22 | }).handle((result, ex) -> {
23 | if (ex != null) {
24 | System.out.println("There was an exception - " + ex.getMessage());
25 | return -1;
26 | }
27 | return result;
28 | });
29 |
30 |
31 | System.out.println("Total points " + future.get());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/src/MultiplesCalculator.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.concurrent.RecursiveTask;
3 |
4 | public class MultiplesCalculator extends RecursiveTask {
5 | private List numbers;
6 | public static int threshold;
7 |
8 | public static int multipleOf;
9 |
10 | public MultiplesCalculator(List numbers) {
11 | this.numbers = numbers;
12 | }
13 |
14 | @Override
15 | protected Integer compute() {
16 | if(numbers.size() <= threshold) {
17 | int count = computeDirectly();
18 | System.out.format("Number of multiples of %d in %s: %d\n", multipleOf, numbers.toString(), count);
19 | return count;
20 | } else {
21 | int mid = numbers.size() / 2;
22 | MultiplesCalculator subTask1 = new MultiplesCalculator(numbers.subList(0, mid));
23 | MultiplesCalculator subTask2 = new MultiplesCalculator(numbers.subList(mid, numbers.size()));
24 |
25 | invokeAll(subTask1, subTask2);
26 |
27 | return subTask1.join() + subTask2.join();
28 | }
29 | }
30 |
31 | protected int computeDirectly() {
32 | int count = 0;
33 | for (Integer n: numbers) {
34 | if (n % multipleOf == 0) {
35 | count +=1;
36 | }
37 | }
38 | return count;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/src/CompletableFutureDemo2.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.CompletableFuture;
2 | import java.util.concurrent.ExecutionException;
3 | import java.util.concurrent.TimeUnit;
4 |
5 | public class CompletableFutureDemo2 {
6 | public static void main(String[] args) throws ExecutionException, InterruptedException {
7 | // Chaining two dependant features
8 |
9 | // Retrieve number of points from a remote database call
10 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
11 | System.out.println("Accessing customer loyalty points data over the network...");
12 | try {
13 | TimeUnit.SECONDS.sleep(4);
14 | } catch (InterruptedException e) {
15 | throw new RuntimeException(e);
16 | }
17 | return 200;
18 | }).thenCompose(result ->CompletableFuture.supplyAsync(() -> {
19 | // Adding bonus points
20 | int totalPoints = result;
21 | if(result >= 10 && result <= 100) {
22 | totalPoints += 10;
23 | } else if(result >= 101 && result <= 200) {
24 | totalPoints += 20;
25 | }
26 | return totalPoints;
27 | }
28 | ));
29 |
30 | System.out.println("Total points " + future.get());
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/src/CopyOnWriteArrayListUseDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.ListIterator;
2 | import java.util.concurrent.CopyOnWriteArrayList;
3 |
4 | public class CopyOnWriteArrayListUseDemo {
5 | CopyOnWriteArrayList copyOnWriteList = new CopyOnWriteArrayList<>();
6 |
7 | public CopyOnWriteArrayListUseDemo() {
8 | copyOnWriteList.add("Sam");
9 | copyOnWriteList.add("John");
10 | copyOnWriteList.add("Bob");
11 | copyOnWriteList.add("Pat");
12 | }
13 |
14 | public void iterateList() {
15 | Thread thread1 = new Thread(()-> {
16 | ListIterator iterator = copyOnWriteList.listIterator();
17 | while (iterator.hasNext()) {
18 | System.out.println(iterator.next());
19 | }
20 | });
21 |
22 | thread1.start();
23 | }
24 |
25 | public void modifyList() {
26 | Thread thread2 = new Thread(()-> {
27 | for(int i = 0; i < copyOnWriteList.size(); i++) {
28 | if(i == 2)
29 | copyOnWriteList.remove(i);
30 | }
31 | });
32 |
33 | thread2.start();
34 | }
35 |
36 |
37 | public static void main(String[] args) {
38 | CopyOnWriteArrayListUseDemo demo = new CopyOnWriteArrayListUseDemo();
39 |
40 | demo.iterateList();
41 | demo.modifyList();
42 | demo.iterateList();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/src/ConcurrentHashMapUseDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.Iterator;
2 | import java.util.concurrent.ConcurrentHashMap;
3 |
4 | public class ConcurrentHashMapUseDemo {
5 |
6 | ConcurrentHashMap productMap = new ConcurrentHashMap<>();
7 |
8 | public ConcurrentHashMapUseDemo() {
9 | productMap.put(100,"TV");
10 | productMap.put(101,"Laptop");
11 | productMap.put(102,"Blender");
12 | productMap.put(103,"Cooker");
13 | }
14 |
15 | public void iterateMap() {
16 | Thread thread1 = new Thread(()-> {
17 | Iterator iterator = productMap.keySet().iterator();
18 | while (iterator.hasNext()) {
19 | System.out.println(productMap.get(iterator.next()));
20 | }
21 | });
22 |
23 | thread1.start();
24 | System.out.println();
25 | }
26 |
27 | public void modifyMap() {
28 | Thread thread2 = new Thread(()-> {
29 | for(int key : productMap.keySet()) {
30 | if(key == 102)
31 | productMap.remove(key);
32 | }
33 | });
34 |
35 | thread2.start();
36 | }
37 |
38 |
39 | public static void main(String[] args) {
40 | ConcurrentHashMapUseDemo demo = new ConcurrentHashMapUseDemo();
41 | demo.iterateMap();
42 | demo.modifyMap();
43 | demo.iterateMap();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/src/ConcurrentHashMapCreateDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.ConcurrentHashMap;
2 |
3 | public class ConcurrentHashMapCreateDemo {
4 | public static void main(String[] args) {
5 | /*
6 | Creates a new empty map with a default capacity of 16
7 | i.e. the internal HashTable size is 16 segments.
8 | a default load factor 0.75 and a concurrency level of 16.
9 | */
10 | ConcurrentHashMap productMap1 = new ConcurrentHashMap<>();
11 | /*
12 | Crates a new empty map with the specified capacity
13 | i.e. table size accommodating the specified number of segments
14 | without the need to dynamically resize,
15 | the default load factor and a concurrency level of 16.
16 | */
17 |
18 | ConcurrentHashMap productMap2 = new ConcurrentHashMap<>(10);
19 |
20 | /*
21 | Creates a new empty map with the specified capacity and specified load factor.
22 | and has a default concurrency level of 16.
23 | */
24 |
25 | ConcurrentHashMap productMap3 = new ConcurrentHashMap<>(10, 0.85f);
26 |
27 | /*
28 | Creates a new empty map with the specified capacity, load Factor,
29 | and concurrency level - and number of concurrently updating threads
30 | */
31 |
32 | ConcurrentHashMap productMap4 =
33 | new ConcurrentHashMap<>(10, 0.85f, 10);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/src/CompletableFutureDemo3.java:
--------------------------------------------------------------------------------
1 | import java.time.DayOfWeek;
2 | import java.time.LocalDate;
3 | import java.util.concurrent.CompletableFuture;
4 | import java.util.concurrent.ExecutionException;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | public class CompletableFutureDemo3 {
8 | public static void main(String[] args) throws ExecutionException, InterruptedException {
9 | // Combining two independent features
10 |
11 | // Retrieve number of points from a remote database call
12 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
13 | System.out.println("Accessing customer loyalty points data over the network...");
14 | try {
15 | TimeUnit.SECONDS.sleep(4);
16 | } catch (InterruptedException e) {
17 | throw new RuntimeException(e);
18 | }
19 | return 200;
20 | }).thenCombine(CompletableFuture.supplyAsync(() -> {
21 | // Calculate points based on day
22 | LocalDate today = LocalDate.now();
23 | DayOfWeek dayOfWeek = today.getDayOfWeek();
24 | if(dayOfWeek.equals(DayOfWeek.WEDNESDAY)) {
25 | return 5;
26 | } else if(dayOfWeek.equals(DayOfWeek.SATURDAY) || dayOfWeek.equals(DayOfWeek.SUNDAY)) {
27 | return 10;
28 | }
29 | return 0;
30 | }), (res1, res2) -> res1 + res2);
31 |
32 |
33 | System.out.println("Total points " + future.get());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_05/src/VotingSimulator.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.Random;
4 | import java.util.concurrent.*;
5 |
6 | public class VotingSimulator {
7 |
8 | private static int noOfVotes = 0;
9 | private static final int VOTERS = 25;
10 |
11 | public static void main(String[] args) throws InterruptedException {
12 | Candidate candidate1 = new Candidate("C1");
13 | Candidate candidate2 = new Candidate("C2");
14 | Candidate candidate3 = new Candidate("C3");
15 |
16 | List candidateList = new ArrayList<>();
17 | candidateList.add(candidate1);
18 | candidateList.add(candidate2);
19 | candidateList.add(candidate3);
20 |
21 | // Write code here to create two tasks - voting & counting and execute them using a scheduled executor service
22 |
23 |
24 | // This code is for continuing voting until the number of votes reaches the number of voters
25 | while (noOfVotes != VOTERS) {
26 | TimeUnit.MILLISECONDS.sleep(100);
27 | }
28 |
29 | // Printing that the voting is ending as all voters have voted
30 | System.out.println("All voters have voted. Ending voting....");
31 | // Write code here to cancel the voting task
32 |
33 | /* Write code here to wait for a maximum of 1 second until all tasks have completed execution
34 | i.e. this is done to give enough time for the counting task to execute, before shutting down the executor.
35 | Hint: use the awaitTermination() method */
36 |
37 | }
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06b/src/VotingSimulator.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.Random;
4 | import java.util.concurrent.*;
5 |
6 | public class VotingSimulator {
7 |
8 | private static int noOfVotes = 0;
9 | private static final int VOTERS = 25;
10 |
11 | public static void main(String[] args) throws InterruptedException {
12 | Candidate candidate1 = new Candidate("C1");
13 | Candidate candidate2 = new Candidate("C2");
14 | Candidate candidate3 = new Candidate("C3");
15 |
16 | List candidateList = new ArrayList<>();
17 | candidateList.add(candidate1);
18 | candidateList.add(candidate2);
19 | candidateList.add(candidate3);
20 |
21 | // Write code here to create two tasks - voting & counting and execute them using a scheduled executor service
22 |
23 |
24 | // This code is for continuing voting until the number of votes reaches the number of voters
25 | while (noOfVotes != VOTERS) {
26 | TimeUnit.MILLISECONDS.sleep(100);
27 | }
28 |
29 | // Printing that the voting is ending as all voters have voted
30 | System.out.println("All voters have voted. Ending voting....");
31 | // Write code here to cancel the voting task
32 |
33 | /* Write code here to wait for a maximum of 1 second until all tasks have completed execution
34 | i.e. this is done to give enough time for the counting task to execute, before shutting down the executor.
35 | Hint: use the awaitTermination() method */
36 |
37 | }
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/src/VirtualThreadDemo.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.ExecutionException;
2 | import java.util.concurrent.ExecutorService;
3 | import java.util.concurrent.Executors;
4 | import java.util.concurrent.Future;
5 |
6 | public class VirtualThreadDemo {
7 | public static void main(String[] args) throws InterruptedException {
8 |
9 | Runnable task = () -> System.out.printf("Thread " + Thread.currentThread());
10 |
11 | Thread t1 = Thread.startVirtualThread(task);
12 | t1.join();
13 |
14 | System.out.println();
15 |
16 | Thread t2 = Thread.ofVirtual().unstarted(task);
17 | t2.start();
18 | t2.join();
19 |
20 | System.out.println();
21 |
22 | Runnable task2 = () -> System.out.println(Thread.currentThread().getName() + " created from builder is running a task");
23 |
24 | Thread.Builder builder = Thread.ofVirtual().name("Virtual Thread", 1);
25 |
26 | Thread builderT1 = builder.start(task2);
27 | Thread builderT2 = builder.start(task2);
28 | Thread builderT3 = builder.start(task2);
29 | Thread builderT4 = builder.start(task2);
30 |
31 | builderT1.join();
32 | builderT2.join();
33 | builderT3.join();
34 | builderT4.join();
35 |
36 | try (ExecutorService myExecutor = Executors.newVirtualThreadPerTaskExecutor()) {
37 | for(int i = 0; i < 100; i++) {
38 | Future> future = myExecutor.submit(() -> System.out.println("Running task"));
39 | future.get();
40 | }
41 | System.out.println("All tasks completed");
42 | } catch (InterruptedException | ExecutionException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/src/CompletableFutureDemo1.java:
--------------------------------------------------------------------------------
1 | import java.util.concurrent.*;
2 | import java.util.function.Supplier;
3 |
4 | public class CompletableFutureDemo1 {
5 | public static void main(String[] args) throws InterruptedException, ExecutionException {
6 |
7 | // Retrieve number of points from a remote database call
8 | // CompletableFuture future = CompletableFuture.supplyAsync(new Supplier() {
9 | // public Integer get() {
10 | // System.out.println("Accessing customer loyalty points data over the network...");
11 | // try {
12 | // TimeUnit.SECONDS.sleep(4);
13 | // } catch (InterruptedException e) {
14 | // throw new RuntimeException(e);
15 | // }
16 | // return 200;
17 | // }
18 | // });
19 |
20 | CompletableFuture future = CompletableFuture.supplyAsync(() -> {
21 | System.out.println("Accessing customer loyalty points data over the network...");
22 | try {
23 | TimeUnit.SECONDS.sleep(4);
24 | } catch (InterruptedException e) {
25 | throw new RuntimeException(e);
26 | }
27 | return 200;
28 | });
29 |
30 | // Attach a callback to the Future using thenApply()
31 | CompletableFuture futureWithCallback = future.thenApply(result -> {
32 | // Adding bonus points
33 | int totalPoints = result;
34 | if(result >= 10 && result <= 100) {
35 | totalPoints += 10;
36 | } else if(result >= 101 && result <= 200) {
37 | totalPoints += 20;
38 | }
39 | return totalPoints;
40 | });
41 |
42 | // Manually completing with the last cached data
43 | futureWithCallback.complete(150);
44 |
45 | System.out.println("Total points " + futureWithCallback.get());
46 |
47 |
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/src/NumberMagic.java:
--------------------------------------------------------------------------------
1 | import java.math.BigInteger;
2 | import java.util.ArrayList;
3 | import java.util.List;
4 | import java.util.Scanner;
5 | import java.util.concurrent.*;
6 |
7 |
8 | public class NumberMagic {
9 | static int number = 0;
10 | public static void main(String[] args) throws InterruptedException, ExecutionException {
11 | Scanner myObj = new Scanner(System.in);
12 | boolean flag;
13 |
14 | do {
15 | System.out.print("Enter an integer number: ");
16 | try {
17 | number = Integer.parseInt(myObj.nextLine());
18 | flag = false;
19 | } catch (NumberFormatException e) {
20 | System.out.println("Not a valid integer");
21 | flag = true;
22 | }
23 | } while(flag);
24 |
25 | ExecutorService executorService = Executors.newFixedThreadPool(3);
26 |
27 | Callable findSqrt = () -> {
28 | double sqrt = Math.sqrt(number);
29 | return "Square Root of " + number + " is: " + sqrt;
30 | };
31 |
32 | Callable findFactorial = () -> {
33 | BigInteger result = BigInteger.ONE;
34 | for (int i = 2; i <= number; i++)
35 | result = result.multiply(BigInteger.valueOf(i));
36 |
37 | return "Factorial of " + number + " is: " + result;
38 | };
39 |
40 | Callable toBinary = () -> {
41 | String binary = Integer.toBinaryString(number);
42 | return number + " in binary: " + binary;
43 | };
44 |
45 | List> callableTasks = new ArrayList<>();
46 | callableTasks.add(findSqrt);
47 | callableTasks.add(findFactorial);
48 | callableTasks.add(toBinary);
49 |
50 | List> futures = executorService.invokeAll(callableTasks);
51 |
52 |
53 | for(Future future:futures) {
54 | System.out.println(future.get());
55 | }
56 |
57 | executorService.shutdown();
58 |
59 |
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_06/ch03_06e/src/VotingSimulator.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.Random;
4 | import java.util.concurrent.*;
5 |
6 | public class VotingSimulator {
7 |
8 | private static int noOfVotes = 0;
9 | private static final int VOTERS = 25;
10 |
11 | public static void main(String[] args) throws InterruptedException {
12 | Candidate candidate1 = new Candidate("C1");
13 | Candidate candidate2 = new Candidate("C2");
14 | Candidate candidate3 = new Candidate("C3");
15 |
16 | List candidateList = new ArrayList<>();
17 | candidateList.add(candidate1);
18 | candidateList.add(candidate2);
19 | candidateList.add(candidate3);
20 |
21 | ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
22 |
23 | Runnable vote = () -> {
24 | Random random = new Random();
25 | int index = random.nextInt(3);
26 | Candidate candidate = candidateList.get(index);
27 | candidate.getVotes().add(1);
28 | noOfVotes++;
29 | System.out.println("Voted for " + candidate.getName());
30 | };
31 |
32 | Runnable count = () -> {
33 | for(Candidate c : candidateList) {
34 | System.out.println("Candidate " + c.getName() + " has " + c.getVotes().size() + " votes");
35 | }
36 | };
37 |
38 | ScheduledFuture> scheduledFuture1 = scheduledExecutorService.scheduleAtFixedRate(vote, 0, 1, TimeUnit.SECONDS);
39 |
40 | scheduledExecutorService.scheduleWithFixedDelay(count, 5, 1, TimeUnit.SECONDS);
41 |
42 |
43 | while (noOfVotes != VOTERS) {
44 | TimeUnit.MILLISECONDS.sleep(100);
45 | }
46 |
47 | System.out.println("All voters have voted. Voting ended!");
48 | scheduledFuture1.cancel(true);
49 |
50 | try {
51 | if (!scheduledExecutorService.awaitTermination(1, TimeUnit.SECONDS)) {
52 | scheduledExecutorService.shutdownNow();
53 | }
54 | } catch (InterruptedException e) {
55 | scheduledExecutorService.shutdownNow();
56 | }
57 | }
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_03/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | {
14 | "customColor": "",
15 | "associatedIndex": 6
16 | }
17 |
18 |
19 |
20 |
21 |
22 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 1694325967834
48 |
49 |
50 | 1694325967834
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_05/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | {
14 | "customColor": "",
15 | "associatedIndex": 6
16 | }
17 |
18 |
19 |
20 |
21 |
22 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 1694325967834
48 |
49 |
50 | 1694325967834
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_01/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 8
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | 1699447086103
54 |
55 |
56 | 1699447086103
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_05/src/MultiplesCalculatorMain.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.Random;
3 | import java.util.Scanner;
4 |
5 | import static java.util.stream.Collectors.toList;
6 |
7 | public class MultiplesCalculatorMain {
8 | public static void main(String[] args) {
9 | int listSize = 0;
10 | int divisor = 0;
11 | int threshold = 0;
12 |
13 | Scanner input1 = new Scanner(System.in);
14 | Scanner input2 = new Scanner(System.in);
15 | Scanner input3 = new Scanner(System.in);
16 | boolean flag;
17 |
18 | String GREEN = "\u001B[32m";
19 | String BLUE = "\u001B[34m";
20 | String RED = "\u001B[31m";
21 | String RESET = "\u001B[0m";
22 |
23 | System.out.println(GREEN + "Enter list size, divisor and a threshold value to calculate the number of " +
24 | "multiples in a list of random integers." + RESET);
25 |
26 | do {
27 | System.out.print(BLUE + "List size (< 10 million): " + RESET);
28 | try {
29 | listSize = Integer.parseInt(input1.nextLine());
30 | flag = !(listSize <= 10_000_000);
31 | } catch (NumberFormatException e) {
32 | System.out.println(RED + "Not a valid integer" + RESET);
33 | flag = true;
34 | }
35 | } while(flag);
36 |
37 | do {
38 | System.out.print(BLUE + "Divisor (between 1 & 10): " + RESET);
39 | try {
40 | divisor = Integer.parseInt(input2.nextLine());
41 | flag = !(divisor <= 10);
42 | } catch (NumberFormatException e) {
43 | System.out.println(RED + "Not a valid integer" + RESET);
44 | flag = true;
45 | }
46 | } while(flag);
47 |
48 | do {
49 | System.out.print(BLUE + "Threshold: " + RESET);
50 | try {
51 | threshold = Integer.parseInt(input3.nextLine());
52 | flag = false;
53 | } catch (NumberFormatException e) {
54 | System.out.println(RED + "Not a valid integer" + RESET);
55 | flag = true;
56 | }
57 | } while(flag);
58 |
59 | Random random = new Random();
60 | List data = random
61 | .ints(listSize, 1, 100)
62 | .boxed()
63 | .collect(toList());
64 |
65 | MultiplesCalculator.multipleOf = divisor;
66 | MultiplesCalculator.threshold = threshold;
67 | // Add code to create the ForkJoinPool here
68 |
69 | // Add code to Instanciate the task here
70 |
71 | // Add code to print the total number of Multiples here
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06b/src/MultiplesCalculatorMain.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.Random;
3 | import java.util.Scanner;
4 |
5 | import static java.util.stream.Collectors.toList;
6 |
7 | public class MultiplesCalculatorMain {
8 | public static void main(String[] args) {
9 | int listSize = 0;
10 | int divisor = 0;
11 | int threshold = 0;
12 |
13 | Scanner input1 = new Scanner(System.in);
14 | Scanner input2 = new Scanner(System.in);
15 | Scanner input3 = new Scanner(System.in);
16 | boolean flag;
17 |
18 | String GREEN = "\u001B[32m";
19 | String BLUE = "\u001B[34m";
20 | String RED = "\u001B[31m";
21 | String RESET = "\u001B[0m";
22 |
23 | System.out.println(GREEN + "Enter list size, divisor and a threshold value to calculate the number of " +
24 | "multiples in a list of random integers." + RESET);
25 |
26 | do {
27 | System.out.print(BLUE + "List size (< 10 million): " + RESET);
28 | try {
29 | listSize = Integer.parseInt(input1.nextLine());
30 | flag = !(listSize <= 10_000_000);
31 | } catch (NumberFormatException e) {
32 | System.out.println(RED + "Not a valid integer" + RESET);
33 | flag = true;
34 | }
35 | } while(flag);
36 |
37 | do {
38 | System.out.print(BLUE + "Divisor (between 1 & 10): " + RESET);
39 | try {
40 | divisor = Integer.parseInt(input2.nextLine());
41 | flag = !(divisor <= 10);
42 | } catch (NumberFormatException e) {
43 | System.out.println(RED + "Not a valid integer" + RESET);
44 | flag = true;
45 | }
46 | } while(flag);
47 |
48 | do {
49 | System.out.print(BLUE + "Threshold: " + RESET);
50 | try {
51 | threshold = Integer.parseInt(input3.nextLine());
52 | flag = false;
53 | } catch (NumberFormatException e) {
54 | System.out.println(RED + "Not a valid integer" + RESET);
55 | flag = true;
56 | }
57 | } while(flag);
58 |
59 | Random random = new Random();
60 | List data = random
61 | .ints(listSize, 1, 100)
62 | .boxed()
63 | .collect(toList());
64 |
65 | MultiplesCalculator.multipleOf = divisor;
66 | MultiplesCalculator.threshold = threshold;
67 | // Add code to create the ForkJoinPool here
68 |
69 | // Add code to Instanciate the task here
70 |
71 | // Add code to print the total number of Multiples here
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_06/ch04_06e/src/MultiplesCalculatorMain.java:
--------------------------------------------------------------------------------
1 | import java.util.List;
2 | import java.util.Random;
3 | import java.util.Scanner;
4 | import java.util.concurrent.ForkJoinPool;
5 |
6 | import static java.util.stream.Collectors.toList;
7 |
8 | public class MultiplesCalculatorMain {
9 | public static void main(String[] args) {
10 | int listSize = 0;
11 | int divisor = 0;
12 | int threshold = 0;
13 |
14 | Scanner input1 = new Scanner(System.in);
15 | Scanner input2 = new Scanner(System.in);
16 | Scanner input3 = new Scanner(System.in);
17 | boolean flag;
18 |
19 | String GREEN = "\u001B[32m";
20 | String BLUE = "\u001B[34m";
21 | String RED = "\u001B[31m";
22 | String RESET = "\u001B[0m";
23 |
24 | System.out.println(GREEN + "Enter list size, divisor and a threshold value to calculate the number of " +
25 | "multiples in a list of random integers." + RESET);
26 |
27 | do {
28 | System.out.print(BLUE + "List size (< 10 million): " + RESET);
29 | try {
30 | listSize = Integer.parseInt(input1.nextLine());
31 | flag = !(listSize <= 10_000_000);
32 | } catch (NumberFormatException e) {
33 | System.out.println(RED + "Not a valid integer" + RESET);
34 | flag = true;
35 | }
36 | } while(flag);
37 |
38 | do {
39 | System.out.print(BLUE + "Divisor (between 1 & 10): " + RESET);
40 | try {
41 | divisor = Integer.parseInt(input2.nextLine());
42 | flag = !(divisor <= 10);
43 | } catch (NumberFormatException e) {
44 | System.out.println(RED + "Not a valid integer" + RESET);
45 | flag = true;
46 | }
47 | } while(flag);
48 |
49 | do {
50 | System.out.print(BLUE + "Threshold: " + RESET);
51 | try {
52 | threshold = Integer.parseInt(input3.nextLine());
53 | flag = false;
54 | } catch (NumberFormatException e) {
55 | System.out.println(RED + "Not a valid integer" + RESET);
56 | flag = true;
57 | }
58 | } while(flag);
59 |
60 | Random random = new Random();
61 | List data = random
62 | .ints(listSize, 1, 100)
63 | .boxed()
64 | .collect(toList());
65 |
66 | MultiplesCalculator.multipleOf = divisor;
67 | MultiplesCalculator.threshold = threshold;
68 | ForkJoinPool pool = new ForkJoinPool();
69 | MultiplesCalculator task = new MultiplesCalculator(data);
70 | System.out.println("Total number of Multiples: " + pool.invoke(task));
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_02/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 4
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | 1695797365150
57 |
58 |
59 | 1695797365150
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_01/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 6
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | 1694064291904
62 |
63 |
64 | 1694064291904
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/source/01-Synchronization/ch01_02/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | {
14 | "customColor": "",
15 | "associatedIndex": 6
16 | }
17 |
18 |
19 |
20 |
21 |
22 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | 1694325967834
56 |
57 |
58 | 1694325967834
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Advanced Java: Threads and Concurrency
2 | This is the repository for the LinkedIn Learning course `Advanced Java: Threads and Concurrency`. The full course is available from [LinkedIn Learning][lil-course-url].
3 |
4 | ![lil-thumbnail-url]
5 |
6 | Are you looking to boost your Java skills? In this course, join instructor and Java expert Buddhini Samarakkody as she provides an overview of Java threads and the new concurrent programming model. Buddhini covers topics in synchronization such as Java thread memory access and associated problems such as race condition and data race. Explore the purpose of synchronization and how to use it, before turning to asynchronous programming with Future and CompletableFuture. Buddhini shows you how to use executors, the fork/join framework and its core classes, concurrent data structures, Project Loom, and virtual threads. Along the way, be sure to test out your new skills in the exercise challenges at the end of each section.
7 |
8 | _See the readme file in the main branch for updated instructions and information._
9 |
10 | ## Instructions
11 | This repository has branches for each of the videos in the course. You can use the branch pop up menu in github to switch to a specific branch and take a look at the course at that stage, or you can add `/tree/BRANCH_NAME` to the URL to go to the branch you want to access.
12 |
13 | ## Branches
14 | The branches are structured to correspond to the videos in the course. The naming convention is `CHAPTER#_MOVIE#`. As an example, the branch named `02_03` corresponds to the second chapter and the third video in that chapter.
15 | Some branches will have a beginning and an end state. These are marked with the letters `b` for "beginning" and `e` for "end". The `b` branch contains the code as it is at the beginning of the movie. The `e` branch contains the code as it is at the end of the movie. The `main` branch holds the final state of the code when in the course.
16 |
17 | When switching from one exercise files branch to the next after making changes to the files, you may get a message like this:
18 |
19 | error: Your local changes to the following files would be overwritten by checkout: [files]
20 | Please commit your changes or stash them before you switch branches.
21 | Aborting
22 |
23 | To resolve this issue:
24 |
25 | Add changes to git using this command: git add .
26 | Commit changes using this command: git commit -m "some message"
27 |
28 | ### Instructor
29 |
30 | Buddhini Samarakkody
31 |
32 | Java Engineer, Author, Instructor
33 |
34 |
35 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/buddhini-samarakkody?u=104).
36 |
37 |
38 |
39 | [0]: # (Replace these placeholder URLs with actual course URLs)
40 |
41 | [lil-course-url]: https://www.linkedin.com/learning/advanced-java-threads-and-concurrency
42 | [lil-thumbnail-url]: https://media.licdn.com/dms/image/D560DAQFM76Oarhc2VA/learning-public-crop_675_1200/0/1712955344085?e=2147483647&v=beta&t=dPEMZnXIX1uXuEz-ILFKUTyjiWKDd0Px7A29okIq6Z0
43 |
44 |
--------------------------------------------------------------------------------
/source/04-Fork-Join Framework/ch04_04/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 7
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | 1698840564152
70 |
71 |
72 | 1698840564152
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_01/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 0
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | 1700994609852
69 |
70 |
71 | 1700994609852
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 5
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | 1696740075965
83 |
84 |
85 | 1696740075965
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/source/07-Virtual Threads in action/ch07_02/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 0
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | 1700994609852
77 |
78 |
79 | 1700994609852
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/source/02-Asynchronous Programming/ch02_04/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 4
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | 1695797365150
89 |
90 |
91 | 1695797365150
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_04/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 5
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | 1696740075965
91 |
92 |
93 | 1696740075965
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/source/05-Concurrent Data Structures/ch05_03/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | {
21 | "associatedIndex": 8
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | 1699447086103
91 |
92 |
93 | 1699447086103
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | LinkedIn Learning Exercise Files License Agreement
2 | ==================================================
3 |
4 | This License Agreement (the "Agreement") is a binding legal agreement
5 | between you (as an individual or entity, as applicable) and LinkedIn
6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning
7 | exercise files in this repository (“Licensed Materials”), you agree to
8 | be bound by the terms of this Agreement. If you do not agree to these
9 | terms, do not download or use the Licensed Materials.
10 |
11 | 1. License.
12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn
13 | members during their LinkedIn Learning subscription a non-exclusive,
14 | non-transferable copyright license, for internal use only, to 1) make a
15 | reasonable number of copies of the Licensed Materials, and 2) make
16 | derivative works of the Licensed Materials for the sole purpose of
17 | practicing skills taught in LinkedIn Learning courses.
18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject
19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members
20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable
21 | copyright license to distribute the Licensed Materials, except the
22 | Licensed Materials may not be included in any product or service (or
23 | otherwise used) to instruct or educate others.
24 |
25 | 2. Restrictions and Intellectual Property.
26 | - a. You may not to use, modify, copy, make derivative works of, publish,
27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the
28 | Licensed Materials, except as expressly set forth above in Section 1.
29 | - b. Linkedin (and its licensors) retains its intellectual property rights
30 | in the Licensed Materials. Except as expressly set forth in Section 1,
31 | LinkedIn grants no licenses.
32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any
33 | alleged infringement or misappropriation of any intellectual property rights
34 | of any third party based on modifications you make to the Licensed Materials,
35 | ii) any claims arising from your use or distribution of all or part of the
36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold
37 | harmless, and indemnify LinkedIn and its affiliates (and our and their
38 | respective employees, shareholders, and directors) from any claim or action
39 | brought by a third party, including all damages, liabilities, costs and
40 | expenses, including reasonable attorneys’ fees, to the extent resulting from,
41 | alleged to have resulted from, or in connection with: (a) your breach of your
42 | obligations herein; or (b) your use or distribution of any Licensed Materials.
43 |
44 | 3. Open source. This code may include open source software, which may be
45 | subject to other license terms as provided in the files.
46 |
47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS”
48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY,
49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY
50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR
51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR
52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS
53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING
54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A
55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT.
56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND
57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE
58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR
59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR
60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT
61 | EXPRESSLY STATED IN THESE TERMS.
62 |
63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT,
64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING
65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER
66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU
67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL:
68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT,
69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT
70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS
71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND
72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR
73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE
74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS.
75 |
76 | 6. Termination. This Agreement automatically terminates upon your breach of
77 | this Agreement or termination of your LinkedIn Learning subscription. On
78 | termination, all licenses granted under this Agreement will terminate
79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this
80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue
81 | the availability of some or all of the Licensed Materials at any time for any
82 | reason.
83 |
84 | 7. Miscellaneous. This Agreement will be governed by and construed in
85 | accordance with the laws of the State of California without regard to conflict
86 | of laws principles. The exclusive forum for any disputes arising out of or
87 | relating to this Agreement shall be an appropriate federal or state court
88 | sitting in the County of Santa Clara, State of California. If LinkedIn does
89 | not act to enforce a breach of this Agreement, that does not mean that
90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does
91 | not create a partnership, agency relationship, or joint venture between the
92 | parties. Neither party has the power or authority to bind the other or to
93 | create any obligation or responsibility on behalf of the other. You may not,
94 | without LinkedIn’s prior written consent, assign or delegate any rights or
95 | obligations under these terms, including in connection with a change of
96 | control. Any purported assignment and delegation shall be ineffective. The
97 | Agreement shall bind and inure to the benefit of the parties, their respective
98 | successors and permitted assigns. If any provision of the Agreement is
99 | unenforceable, that provision will be modified to render it enforceable to the
100 | extent possible to give effect to the parties’ intentions and the remaining
101 | provisions will not be affected. This Agreement is the only agreement between
102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior
103 | agreements relating to the Licensed Materials.
104 |
105 | Last Updated: March 2019
106 |
--------------------------------------------------------------------------------
/source/03-Executors/ch03_03/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------