September 1, 2022July 25, 2023 Java 8 Concurrency (2023) In simple words, concurrency is the ability to run several programs or several parts of a program in parallel. Concurrency enables a program to achieve high performance and throughput by utilizing the untapped capabilities of the underlying operating system and machine hardware. For example, modern computers have several CPUs or several cores within one CPU, the program can utilize all cores for some part of the processing; thus completing tasks much before in time in comparison to sequential processing. The backbone of java concurrency is threading. A thread is a lightweight process that has its own call stack, but can access shared data of other threads in the same process. A Java application runs by default in one process. You can work with many threads within a Java application to achieve parallel processing or concurrency. 1. What makes a Java Application Concurrent? In the very first class, you will need to make a java class concurrent, is java.lang.Thread class. This class is the basis of all concurrency concepts in java. Then you have java.lang.Runnable an interface to abstract the thread behavior out of the thread class. Other classes you will need to build advanced applications can be found at java.util.concurrent package, added in Java 1.5. 2. Is Java Concurrency Really That Simple? The above description gives the impression that concurrency is indeed a good concept, and is very easy to implement. Well, it is not. It requires a good amount of understanding of the basic concepts and a clear understanding of application goals. Concurrent applications usually have more complex designs in comparison to single-threaded applications. Code executed by multiple threads accessing shared data needs special attention. Errors arising from incorrect thread synchronization are very hard to detect, reproduce and fix. They usually show up in higher environments like production, and replicating the error is sometimes not possible in lower environments. Apart from complex defects, concurrency requires more resources to run the application. So make sure, you have sufficient resources in your kitty. 3. Java Concurrency Tutorial Covering whole java concurrency in a single post is simply almost impossible. So, I have written below Java Concurrency Tutorials discussing one individual concept in a single post. Go through these tutorials, and let me know if you have any questions or suggestions. 3.1. Java Concurrency Basics What is Thread Safety? Object level locking and class level locking wait(), notify() and notifyAll() methods How to Create and Start a New Thread in Java Set and Get the Name of Thread Kill a Thread Java Thread Join Thread Priority 3.2. Difference between Difference between “implements Runnable” and “extends Thread” Difference between yield() and join() Difference between sleep() and wait()? 3.3. Executor Framework Executor Framework Tutorial ExecutorService shutdown(), shutdownNow() and awaitTermination() ExecutorService invokeAll() ExecutorService invokeAny() Waiting for Threads to Finish Cancel a task with ExecutorService 3.5. Concurrent Collections ConcurrentHashMap Example 3.7. Miscellaneous Creating and resolving Deadlock Concurrency Java concurrencyconcurrency basicsconcurrency in javaconcurrency in java 8concurrency in java 8 exampleconcurrency in java questionsconcurrency in java tutorialconcurrency tutorialconcurrency vs parallelismexecutorexecutor frameworkexecutor framework hierarchyexecutor framework in javaexecutor framework in java 8 exampleexecutor framework in java exampleexecutor framework in java tutorialexecutor framework tutorialexecutor serviceexecutorsexecutors frameworkfeel concurrencyhandling uncaught exception in executor frameworkimportance of java concurrencyjavajava basicsjava concurrencyjava concurrency & multithreadingjava concurrency examplejava concurrency full coursejava concurrency interview questionjava concurrency tutorialjava concurrency tutorial by techtalk debujava concurrency tutorial with examplesjava concurrency utils tutorialjava executor frameworkjava executors frameworkjava executors framework apisjava interview questions and answersjava multi threadingjava multi threading tricky interview questionjava multithreadingjava multithreading tutorialjava threading and concurrencyjava threadsjava tutorialjava tutorial for beginnersjava.util.concurrent package tutorialjava.util.concurrent tutorialmultithreading and concurrencymultithreading and concurrency in javamultithreading in javathread executorthread pools and the executor framework in javatricky java interview questions for experiencedTypes of Thread Priority