- Lock objects support locking idioms that simplify many concurrent applications.
- Executors define a high-level API for launching and managing threads. Executor implementations provided by java.util.concurrent provide thread pool management suitable for large-scale applications.
- Concurrent collections make it easier to manage large collections of data, and can greatly reduce the need for synchronization.
- Atomic variables have features that minimize synchronization and help avoid memory consistency errors.
- ThreadLocalRandom (in JDK 7) provides efficient generation of pseudorandom numbers from multiple threads.
This deadlock can be solved by putting same order of lock for Integer and String class in method m1 and m2.
Below is the example of ExecutorService using cachedThreadPool. This is using Callable instance, which does the task and return the result to calling programme.
10. What is Thread Pools ?
Using the fork/join framework is simple. The first step is to write some code that performs a segment of the work. Your code should look similar to this:
Wrap this code as a ForkJoinTask subclass, typically as one of its more specialized types RecursiveTask(which can return a result) or RecursiveAction.