ARVIND KRISHNAA J CSE 'A' III YEAR MULTITHREADING CONCEPTS
CONTENTS Thread safe collections
Executors
Synchronizers
Threads and swing
THREAD SAFE COLLECTIONS Multiple concurrently running threads modifying a data structure may possibly damage it.
Choices to avoid this are: Supplying a lock for the data structure
Choose a thread safe implementation of the data structure
AVAILABLE THREAD SAFE COLLECTIONS BLOCKING QUEUES
EFFICIENT MAPS
SETS
BLOCKING QUEUES WHERE CAN IT BE USED : Consider the case of the producer-consumer problem.
One thread insert items into the queue. Another removes an item.
FUNCTIONALITY:  Causes a thread to block when an element is being added to a full queue (or) when an element is being removed from an empty queue.
BLOCKING QUEUES (contd) Methods available : java.util.concurrent
(1)  Constructors available : Interface BlockingQueue<E> (i) ArrayBlockingQueue(int capacity)
(ii) ArrayBlockingQueue(int capacity,boolean fair) fair - if true then queue accesses for threads blocked on insertion or removal, are processed in FIFO order; if false the access order is unspecified. (iii) LinkedBlockingQueue()
LinkedBlockingDeque()
LinkedBlockingQueue(int capacity)
LinkedBlockingDeque(int capacity)
BLOCKING QUEUES(contd) DelayQueue(): Creates a new unbounded blocking queue in which only those elements whose delay has expired can be removed from the queue.
PriorityBlockingQueue()
PriorityBlockingQueue(int initialcapacity)
(initial capacity is 11 by default)
PriorityBlockingQueue(int initialcapacity,Comparator <? super E> comparator>
Important Methods Blocking queues can be used as
(a) Thread management tool
(b) Synchronization tool
(c) Simple data structure
Methods :
(i) boolean add(E o) throws IllegalStateException: Adds the specified element to the queue

Multithreading Concepts