· BlockingQueue
-
interface - extremely useful in producer-consumer problems
o ArrayBlockingQueue,- implementation of
BlockingQueue interface
o PriorityBlockingQueue - Same as BlockingQueue
but its contents should be comparable either
naturl ordering or by
customizing
o DelayQueue - Same as BlockingQueue but its
contents can be accessed only after certain time say 5 sec.
o SynchronousQueue - A special type of
BlockingQueue with the size of zero.you can insert into it only
when the
consumer is waiting
o LinkedBlockingQueue - linkedlist approach of
ArrayBlockingQueue -- implementation of BlockingQueue
interface
· BlockingDeQueue - Same as BlockingQueue but with Dequque functions
o LinkedBlockingDeque - Same as BlockingQueue but
with linkedlist + Dequque functions
· Java
Thread Pools
o Executor - Its an interface with execute
function.
o Executors Class - its like a factory class that
supports all ExecutorService inteface functions.
o ExecutorService - Interface extends Executor
class, Executor framework.
o ScheduledExecutorService - creates threads upon
specified time.
· ConcurrentMap
o ConcurrentHashMap - HashMap with all methods
synchronized
· ConcurrentNavigableMap
o ConcurrentSkipListMap
· ConcurrentSkipListSet
· ConcurrentLinkedQueue
· CopyOnWriteArrays - thread-safe variant of ArrayList - The collection internally copies
its contents over
to a new array upon any modification, so readers accessing
the contents of the array incur no synchronization
costs
· Callable and Future - callable is alternative to Runnable where object
has to be returned,and Future is
going to hold the returned object.
· Condition Class - Condition factors out the Object monitor methods (wait, notify and
notifyAll) into distinct
objects to give the effect of having multiple
wait-sets per object, by combining them with the use of arbitrary
Lock
implementations.
· CyclicBarrier - allows multiple threads to wait for each other (barrier) before
proceeding.
· CountDownLatch - just a counter need to decrease and call await method till then all
threads after the
current thread are held.
· ReentrantLock Class - alternate to using Synchronized block.
eg:-
private
Lock lock = new ReentrantLock();
lock.lock();
try
{
increment();
}
finally {
lock.unlock();
}
· ReentrantReadWriteLock -
ReentrantLock with additional readlock and writeLock functionalities.
· Semaphore - counter is
greater than zero, then access is allowed. If it is zero, then access is
denied.
use
sem.acquire();,sem.release(); to get the permit and release
· Exchanger - an CLass which
helps to exchange the classes between threads.
· java.util.concurrent.atomic - increment the integer in synchronized way.
ExecutorService service = Executors.newFixedThreadPool(4);//total 4 threads availabe in the pool
new Thread(new FileOperations()).start(); for (int i = 0; i < 2; i++) {
service.submit(new PDFreader());//2 threads given to PDFReader
}
for (int i = 0; i < 2; i++) {
service.submit(new TxtReader());//2 threads given to TxtReader
}