
Source Code attached with this Lecture.
Learn to create and run threads in parallel using the normal threads api and the Executors framework, including fixed-thread-pool, cached-thread-pool, and single-thread-executor, with practical code-along sessions.
Explore the second technique for executing tasks with the threads API by delaying startup until the calling code invokes start on a second task that extends Thread, gaining more control.
Explore the third technique for thread creation using the runnable interface and a separate thread object, enabling ballistic fire-and-forget background tasks such as regular cache invalidation.
Implement the fourth technique using the threads-api by moving thread creation to the main method, capturing the thread reference, and starting execution there for greater control and compatibility with executors.
Explore the fifth technique of the threads API by providing an inline runnable to a thread and starting it directly, emphasizing single-use, event-driven inline tasks for UI events.
Discover how the executors framework simplifies multithreading by submitting runnable tasks to an executor service, which uses thread pools to run and recycle threads, and shut down when done.
Explore the cached thread pool in the executors framework. It creates as many threads as needed to run submitted tasks immediately, with no wait queue and reuse of finished threads.
Explore the single thread executor, a fixed thread pool with pool size one, which serializes tasks and can remove synchronization needs when accessing a shared resource.
Learn to name normal threads and executor pool threads to improve log readability and debugging in multithreaded Java applications, and explore remaining thread pool concepts using earlier naming lessons.
Name normal Java threads with two techniques: name from the running task via currentThread and setName, and name at thread creation, plus why mid-task renaming harms debugging.
Apply the second technique for naming threads at creation or with setName, and adjust tasks to fetch the current thread name to reflect runtime renames.
Understand how to name executor threads by providing a thread factory to the executor, and by naming tasks; use a factory that prefixes pool worker and a sequence number.
Demonstrate thread reuse in a cached thread pool by submitting three tasks, waiting, then five more. Observe three threads handle the new tasks while two new threads are created.
Learn to return values from threads using the normal threads API and the executors framework, and retrieve results from multiple tasks in sequence or as soon as any completes.
Learn the first technique for returning values from normal threads by using a task with a getter that waits for completion using wait/notify and a volatile done flag.
Explore a non-blocking approach to returning values from normal threads using callbacks and an observer pattern, with a generic result listener and task ID to process results as they arrive.
Explore daemon threads by using the threads API and executors API to run background logic that stops when the application closes.
Discover how to create and manage daemon threads with the threads API and executors, using setDaemon and isDaemon, and observe daemon background tasks running until user threads finish.
Build and name daemon threads with a custom thread factory using executors, and see how the JVM terminates daemon threads after user tasks finish.
Learn how to determine if a thread is alive in Java, including the normal threads API and the executors framework, covering running, blocked, and dead states.
Learn to check thread liveness with the isAlive method in the threads API, by starting threads, polling their status, and observing them become non-alive after completion.
Explore techniques to terminate tasks rather than threads, and distinguish between normal threads and executor tasks while learning how to stop blocking and non blocking tasks within the executor framework.
Master the first technique to terminate normal threads by signaling a stop flag inside the task and checking it during execution.
Using the future interface, terminate executor tasks by calling cancel(mayInterruptIfRunning); interrupt running tasks when possible, return true if canceled, false if already completed or not cancelable, and manage queued tasks.
Learn how to terminate blocked executor tasks using future.cancel, handle interrupts in runnable and callable tasks, and ensure clean shutdown of executor services.
Discover how to terminate all executor tasks in one shot with shutdown now, handling interrupts for blocking and non-blocking tasks, and compare graceful vs faulty interruption behavior.
Learn to manage uncaught exceptions across all threads by implementing a thread exception handler and registering a default uncaught exception handler with Thread.setDefaultUncaughtExceptionHandler.
Assign distinct uncaught exception handlers per thread by implementing the uncaught exception handler interface and setting a handler on each thread.
Master handling uncaught exceptions in Java multithreading by combining a default uncaught exception handler with per-thread overrides using thread exception handler and thread exception notifier.
Set a default uncaught exception handler for all executor threads across pools, centralizing error handling. Implement the thread's uncaught exception handler interface and log exceptions to the console.
Apply custom uncaught exception handling in executors by using a named alternating thread factory and an application-wide default handler, illustrating overrides on even versus odd threads.
Discover techniques to make a thread wait for other threads to complete, using normal threads, returning values from tasks, and waiting for tasks in the Executors framework.
Demonstrate the third technique for returning values from normal threads using join to synchronize result retrieval. The lesson replaces wait/notify with join on threads and shows results printed in order.
Learn to use the countdown latch from the executors API to wait for other tasks to finish, including waits for four, two, or any two tasks, with non-reusability noted.
Learn to schedule one-time tasks with normal threads using the timer and timer task APIs, scheduling by exact time or delay, and observe scheduled versus actual execution times.
Schedule one-time tasks with a timer in Java, using daemon versus normal threads, and observe how long-running tasks delay subsequent executions and how canceling tasks works.
Explore fixed-rate task scheduling with timer's scheduleAtFixedRate, ensuring exact periods and no drift, suitable for time-sensitive activities; examine a two-stream example and graceful cancellation.
Schedule tasks for one-time execution using the Executors API with runnable and callable, showing start/end times, run duration, and results across single-thread pools.
Learn to schedule repeated fixed delay tasks with the scheduled executor service, where each next run starts after the previous ends, using initial delay and delay values.
Schedule fixed-delay tasks with a scheduled thread pool that has three threads to prevent interference, and cancel tasks via their future or use shutdown to stop all tasks.
Schedule tasks for fixed-rate repeated executions using scheduleAtFixedRate in the scheduled executor service, ensuring no drift and constant frequency; beware long-running tasks that exceed the period.
Learn all the concepts of Java's Executors API from scratch in combination with parallel concepts of the Threads API. Develop skills and deepen your knowledge of advanced multi-threading concepts by learning various tips & techniques and becoming aware of pitfalls when using Executors API. And ... refresh your advanced Threads-API concepts as well.
Do you know how to return values using the normal Threads API and its Runnables?
Do you know the various ways of terminating threads midway for both the APIs?
Do you know how to 'join threads' using Executors?
Do you know that you cannot catch stray exceptions leaked out from a thread by using try-catch block - neither in the Threads API nor in the Executors one? And that this can lead to third-party code killing your scalable, high-performance and high-availability enterprise application?
Do you know how to check if a task has finished execution using both the APIs?
Do you know what are daemon threads and how to create them using Executors?
Do you know how to name Executor threads?
Do you know the various ways to schedule tasks for running in future using both the APIs? Do you know the various 'types' of scheduling?
If the answer to any of these questions is 'no', then this course is for you (provided that you know Java and the basics of multi-threading already)! Learning from HD quality videos and nearly 6 hours of content will help you convert all these "nos" to "yeses" ... and will also give you an edge over your peers! Not only will this course help you learn how to get things done the multi-threaded way but also how to avoid the mistakes and pitfalls and thereby, increase your efficiency and productivity. All those long bug-fixing hours that you save can be spent finishing your other pending work or even for pleasure!
Avoid the pitfalls while writing multi-threaded code by learning pro-tips
In my 19 years of experience building large enterprise applications, I have made all the mistakes in multi-threading that can be made. And believe me - multi-threading bugs are costly and multi-weekend-destroying to resolve.
I have used my vast experience to craft this course in such a manner so as to highlight the pitfalls that await a programmer and also provide tips to avoid those pitfalls. By going through this course, you will be years ahead of your peers who are yet to make all the mistakes that I have made.
Content and Overview
It is difficult to directly move from an older to a newer way of doing things if you are not comfortable with the older way also - you won't be able to map things from the old way to the new way. So, this course has been structured in such a way that the Threads-API way of doing things are explained first and then the corresponding way to do them using the Executors-API is explained. This will help you understand not only the advanced concepts of Executors but also those of the Threads-API.
So, this course is suitable for programmers who want to learn about the Executors API from scratch. It is also beneficial for those who want to refresh their concepts or learn the techniques of doing various operations using the Threads-API. Detailed examples along with the source-code are provided on every concept for both the APIs.
The course starts with the basics first - 'How to create and run threads', 'How to name the threads' and 'How to return values from threads' - using both the APIs. And then, it gradually moves on to increasingly advanced concepts like 'Terminating Threads', 'Catching Exceptions', 'Waiting for threads to finish without wasting CPU cycles', etc.
BEFORE YOU BUY THIS COURSE, DON'T FORGET TO WATCH THE FREE PREVIEW VIDEO ON 'PRE-REQUISITES AND COURSE STRUCTURE' IN SECTION-1!