"Hi, Amigo!"
16
Task
Java Multithreading,
level 8,
lesson 8
Locked
Introducing Executors
1. In the main method, create a fixed pool of 5 threads using the Executors class.
2. Use a loop to send 10 Runnable tasks to the pool.
3. In each task's run method, call the doExpensiveOperation method using the task's sequence number, starting from 1 (see the sample output).
16
Task
Java Multithreading,
level 8,
lesson 8
Locked
Introducing ThreadPoolExecutor
1. In the main method, create a LinkedBlockingQueue object.
2. Use a loop to add 10 Runnable tasks to the queue.
3. In each task's run method, call the doExpensiveOperation method using the task's sequence number, starting from 1 (see the sample output).
9
Task
Java Multithreading,
level 8,
lesson 8
Locked
shutdownNow!
Understand the difference between the shutdown and shutdownNow methods. Display a list of all the incomplete tasks on the screen.
It should look something like:
pool-1-thread-1, localId=1,
pool-1-thread-2, localId=2,
pool-1-thread-3, localId=3,
pool-1-thread-4, localId=4,
pool-1-thread-5, localId=5.
GO TO FULL VERSION