-
Notifications
You must be signed in to change notification settings - Fork 0
IBM tutorials
illyfrancis edited this page Mar 3, 2014
·
10 revisions
http://www.ibm.com/developerworks/library/j-nothreads/
http://www.ibm.com/developerworks/training/kp/j-kp-concurrency/
-
5 things didn't know about j.u.c part 1
TimeUnitCopyOnWriteArrayListBlockingQueueConcurrentMapSynchronousQueues
-
5 things... part 2
-
Semaphorefor throttling CountDownLatch-
Executorinstead of creatingThreads directlyExecutor exec = getAnExecutorFromSomeplace(); exec.execute(new Runnable() { ... });-
ExecutorServiceExecutorService executor = Executors.newFixedThreadPool(..)
-
CallableandFuture
ScheduledExecutorService- Timeout methods
- also look at
.locksand.atomicpackage,CyclicBarrier
-
-
Java concurrency bug patterns for multicore systems
-
volatilekeyword only guarantees that a variable is visible; it does not guarantee atomicity. - simultaneous locking on updated fields (to fix, use
private finalto ensure the lock object remains unchanged andmutexis guaranteed)
- read through the example but the gist is the synchronized field is updated with a 'different' instance
-
java.util.concurrentlock leak
- i.e. Lock.lock() invocation without unlock() on the same instance causes a lock leak (see below).
-
- Lock leak
private final Lock lock = new ReentrantLock();
public void lockLeak() {
lock.lock();
try {
accessSharedResource(...);
lock.unlock();
} catch (Exception e) {}
}
public void accessSharedResource() throws InterruptedException {...}
Instead put the unlock invocation in the finally block.
public void lockLeak() {
lock.lock();
try {
accessSharedResource(...);
} catch (Exception e) {}
finally {
lock.unlock();
}
}```
2. another
### Actor concurrency
http://www.ibm.com/developerworks/training/kp/j-kp-actorconcurrency/