java concurrency study notes


      ExecutorService es2= Executors.newFixedThreadPool(2);
        ExecutorService es = Executors.newCachedThreadPool();
        ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
        
        ReentrantLock rl = new ReentrantLock();
        ReentrantReadWriteLock rwl = new ReentrantReadWriteLock ();
        SynchronousQueue<Integer> queue = new SynchronousQueue();
        queue.add(null);
        queue.offer(null);
        
        Object a = new Object();
        a.wait(12l);
        
        CountDownLatch cd = new CountDownLatch(1);

CyclicBarrier
        cd.await() ;


Condition implementations may provide behavior and semantics that differ from Object monitor methods, such as guaranteed notification ordering, or the need to hold a lock while performing notifications.

Semaphore: Semaphore
maintains a set of permissions. If necessary, each acquire() is blocked until a license is available, and then the license is acquired. Each release() adds a permission, potentially releasing a blocking acquirer.

Timer
1.AbstractQueuedSynchronizer :

The basic idea behind the synchronizer is very simple. The acquire operation is as follows:

while (synchronization state does not allow acquire) {
enqueue current thread if not already queued;
possibly block current thread;
}
dequeue current thread if it was queued; the
release operation is as follows:

update synchronization state;
if (state may permit a blocked thread to acquire)
unblock one or more queued threads;


the AQS framework provides a ConditionObject class for classes that maintain exclusive synchronization and classes that implement the Lock interface. A lock object can be associated with any number of condition objects
ConditionObject uses the same internal queue nodes as synchronizers. However, these nodes are maintained in a separate condition queue. The signal operation is implemented by transferring the node from the condition queue to the lock queue, without the need to wake up the thread that needs to wake up before it reacquires the lock. The
basic await operation is as follows:

1
create and add new node to conditon queue;
2
release lock;
3
block until node is on lock queue;
4
re-acquire lock;
signal operation is as follows: 1

transfer
the first node from condition queue to lock queue ; 1, workQueue = LinkedBlockingQueue (capacity is Integer.MAX_VALUE) - newCachedThreadPool(): corePoolSize = 0, maximumPoolSize = Integer.MAX_VALUE, keepAliveTime = 60s, workQueue = SynchronousQueue (capacity is 0)





– newFixedThreadPool ( int nThreads ) : corePoolSize = maximumPoolSize = nThreads , keepAliveTime = 0 , workQueue = LinkedBlockingQueue (capacity is Integer.MAX_VALUE )
– newSingleThreadScheduledExecutor () : single thread, delayed execution of tasks
– newScheduledThreadPool ( int corePoolSize ) : corePoolSize , maximum= Integer .MAX_VALUE , keepAliveTime =0 , workQueue = DelayedWorkQueue


http://ifeve.com/introduce-abstractqueuedsynchronizer/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326943340&siteId=291194637
Recommended