There are three classes that implement ExecutorService interface:
1) ThreadPoolExecutor
2) ScheduledThreadPoolExecutor
3) ForkJoinPool
Executors class
- is ...
- includes ...
- is utility class defined in java.util.concurrent
- includes a number of static methods that simplify the creation of various executors.
Other interfaces related to to executors: (2)
1) Future
2) Callable
Future
- is ...
- contains ...
- is interfaces related to to executors
- contains a value that is returned by a thread after it executes
Callable
- is ...
- defines ...
- is interfaces related to to executors
- defines a thread that returns a value.
Concurrent collections
- defined in
- to offer ...
- defined in java.util.concurrent
- to offer concurrent alternatives to their related classes defined by the Collections Framework
concurrent collection classes: (3)
1) ConcurrentHashMap
2) ConcurrentLinkedQueue
3) CopyOnWriteArrayList
Fork/Join Framework
- defined in ...
- supports ...
- defined in java.util.concurrent
- supports parallel programming
Fork/Join Framework classes: (4)
1) ForkJoinTask
2) ForkJoinPool
3) RecursiveTask
4) RecursiveAction
TimeUnit
- is ...
- defined in ...
- to ...
- is enumeration
- defined in java.util.concurrent
- to better handle thread timing
java.util.concurrent.atomic
- is ...
- facilitates ...
- provides ...
- is Concurrent API subpackage
- facilitates the use of variables in a concurrent environment
- provides a means of efficiently updating the value of a variable without the use of locks
java.util.concurrent.atomic has some classes: (2)
1) AtomicInteger
2) AtomicLong
AtomicInteger
- is ...
- has methods (3) ...
- is a class of java.util.concurrent.atomic subpackage
1) boolean compareAndSet(int expect, int update)
- Atomically sets the value to the given updated value if the current value == the expected value.
2) int decrementAndGet()
- Atomically decrements by one the current value.
3) int getAndSet(int newValue)
- Atomically sets to the given value and returns the old value.
AtomicLong
- is ...
- has methods (3) ...
- is a class of java.util.concurrent.atomic subpackage
1) boolean compareAndSet(long expect, long update)
- Atomically sets the value to the given updated value if the current value == the expected value.
2) long decrementAndGet()
- Atomically decrements by one the current value.
3) long getAndSet(long newValue)
- Atomically sets to the given value and returns the old value.
java.util.concurrent.locks
- is ...
- provides ...
- is Concurrent API subpackage
- provides an alternative to the use of synchronized methods.
At the core of java.util.concurrent.locks subpackage is ...
is interface Lock
Lock
- is ...
- has methods (3) ...
- is interface at the core of java.util.concurrent.locks subpackage
1) void lock()
- Acquires the lock.
2) boolean tryLock()
- Acquires the lock only if it is free at the time of invocation
3) void unlock()
- Releases the lock.
another important interface of java.util.concurrent.locks subpackage
ReadWriteLock
ReadWriteLock
- is ...
- has methods (2) ...
- is interface of java.util.concurrent.locks subpackage
1) Lock readLock()
- Returns the lock used for reading.
2) Lock writeLock()
- Returns the lock used for writing.
The major advantage of lock interfaces:
- they provide two separate lock for reading and writing which enables you to write high performance data structure like ConcurrentHashMap and conditional blocking
You have thread T1, T2 and T3, how will you ensure that thread T2 run after T1 and thread T3 run after T2?
- it can be achieved by using join method of Thread class.
What is the advantage of new Lock interface over synchronized block in Java? You need to implement a high performance cache which allows multiple reader but single writer to keep the integrity how will you implement it?