Java Multithreading and Concurrency Training
Java Multithreading and Concurrency Training
Concurrency Training
Multithreading and Concurrency
› What is Single Thread
› What is Multithreading in Java?
› Multithreading in Java
› Threads in Java
› Java Thread Example
› Java Thread Sleep
› Java Thread Join
› Java Thread States
› Java Thread wait, notify and notifyAll
› Java Thread Safety and Java Synchronization
›
If your class provides more functionality rather than just running as Thread, you
should implement Runnable interface to provide a way to run it as Thread. If
your class only goal is to run as Thread, you can extend Thread class.
› Java thread pool manages the collection of Runnable threads. The worker
threads execute Runnable threads from the queue.
java.util.concurrent.Executors provide factory and support methods for
java.util.concurrent.Executor interface to create the thread pool in java.
› Executors is a utility class that also provides useful methods to work with
ExecutorService, ScheduledExecutorService, ThreadFactory, and Callable
classes through various factory methods.
› Java Future provides cancel() method to cancel the associated Callable task. There is an overloaded
version of get() method where we can specify the time to wait for the result, it’s useful to avoid current
thread getting blocked for longer time. There are isDone() and isCancelled() methods to find out the current
status of associated Callable task.
› Here is a simple example of Java Callable task that returns the name of thread executing the task after one
second. We are using Executor framework to execute 100 tasks in parallel and use Java Future to get the
result of the submitted tasks.