Java Reference
In-Depth Information
1312936534890: Thread[pool-1-thread-2,5,main]: doing work
1312936534890: Thread[pool-1-thread-3,5,main]: doing work
main thread doing something else
Youmightobservethe
main thread doing something else
messageap-
pearingbetweenthelast“
entered run()
”messageandthefirst“
doing work
”
message.
Note
For brevity, I have avoided examples that demonstrate
CyclicBarrier
,
Exchanger
,
Phaser
,and
Semaphore
.Instead,IreferyoutotheJavadocumenta-
tionfortheseclasses.Eachclass'sdocumentationprovidesanexamplethatshowsyou
how to use the class.
Concurrent Collections
The
java.util.concurrent
package includes several interfaces and classes that
•
BlockingDeque
is a subinterface of
BlockingQueue
and
java.util.Deque
that also supports blocking operations that wait for the
dequetobecomenonemptybeforeretrievinganelement,andwaitforspaceto
becomeavailableinthedequebeforestoringanelement.The
LinkedBlock-
ingDeque
class implements this interface.
•
BlockingQueue
is a subinterface of
java.util.Queue
that also sup-
portsblockingoperationsthatwaitforthequeuetobecomenonemptybeforere-
trievinganelement,andwaitforspacetobecomeavailableinthequeuebefore
storing an element. Each of the
ArrayBlockingQueue
,
DelayQueue
,
LinkedBlockingDeque
,
LinkedBlockingQueue
,
LinkedTrans-
ferQueue
,
PriorityBlockingQueue
, and
SynchronousQueue
classes implements this interface.
•
ConcurrentMap
is a subinterface of
java.util.Map
that declares ad-
ditional atomic
putIfAbsent()
,
remove()
, and
replace()
methods.
The
ConcurrentHashMap
class (the concurrent equivalent of
java.util.HashMap
)andthe
ConcurrentSkipListMap
classimple-
ment this interface.
•
ConcurrentNavigableMap
is a subinterface of
ConcurrentMap
and
java.util.NavigableMap
. The
ConcurrentSkipListMap
class
implements this interface.