Submitted by heartin on Thu, 07/04/2013 - 01:22
A Future interface is used to represent the result of an asynchronous computation in Java concurrency. A Future interface provides methods to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result is retrieved using its get method when the computation has completed, and it blocks until it is completed. Cancellation is performed by the cancel method (cancel(boolean mayInterruptIfRunning)).
Submitted by heartin on Wed, 07/03/2013 - 20:01
A latch is a synchronizer that acts as a gate by delaying the progress of threads until it reaches a particular state. Once it reaches the terminal state, it cannot change state again and hence remains open forever. CountDownLatch is a latch implementation that allows one or more threads to wait for a particular state. A counter is initialized to a positive number. The countDown method decrements the counter, and the await methods wait for the counter to reach zero or until the waiting thread is interrupted, or the wait times out.
Submitted by heartin on Tue, 02/05/2013 - 19:22
When several threads try to access a single resource, there is a chance that it might corrupt that data. Synchronization is the process which ensures that, when several threads want to access a single resource, only one thread can access it at any given time; other threads trying to access will have to wait for its turn.
Important points about Synchronization
-
A synchronized region is guarded by a lock object.
Submitted by heartin on Tue, 02/05/2013 - 19:06
Thread class has many important methods like init, start, stop, run, getName(), getPriority(), isAlive() and join(), and also few static methods like sleep(), yield() etc.
Submitted by heartin on Tue, 01/22/2013 - 09:47
The producer consumer problem describes two processes, the producer and consumer, who share a common fixed size buffer used as a queue. The producer generates data and put data into buffer continuously. At the same time, the consumer will be consuming the data continuously. The problem is to make sure that producer won’t try to add data into buffer if it is full and that the consumer won’t try to remove data from an empty buffer.
Pages