














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















!" ! !
Thread, synchronized, wait(),notify()…
java.util.concurrent
% "
" !&
' (
)
(
*
+" ,
" !&-
"
.
() *
"
"
"
java.nio
)
java.util.concurrent.locks
4
" !&
*!
lock(),
unlock()
tryLock()
tryLock(time, unit)
ReentrantLock
ReentrantReadWriteLock
" *" "
" " $
Condition
class BoundedBuffer {
final Lock
lock
=
new ReentrantLock();
final Condition
notFull
=
lock.newCondition();
final Condition
notEmpty
=
lock.newCondition();
public void put (Object x)
throws InterruptedException {
lock.lock
();
try {
while (count == items.length)
notFull.await
();
items[putptr] = x;if (++putptr == items.length)
putptr = 0;
++count; notEmpty.signal
();
} finally {
lock.unlock
(); }
}
public Object take()
throws InterruptedException {
lock.lock
();
try {
while (count == 0)
notEmpty.await
();
Object x = items[takeptr];if (++takeptr == items.length)
takeptr = 0;
--count; notFull.signal
();
return x;
} finally {
lock.unlock
(); } }
}
AtomicInteger
set(int)
get()
addAndGet(int),
incrementAndGet()
getAndAdd(int),
getAndIncrement()
compareAndSet(expected,update)
2 "
!
" , ,
** !
778 !,
+
** !!*
" !& , " "
*"
AtomicReference
set(V newValue)
get()
compareAndSet(expected,update)
getAndSet(newValue)
9 "
,
% :# ;
% 7< , =
# > 87%
9
2
:< , (
% (
# ;
"
, - $ . / - , (0 /
9
2
:% , (
% (
8;
9 %
+ )
% :# ;
% 7< , =
# > 87%
9
2
:< , (
% (
# ;
"
, - $ . / - , (0 /
9
2
:% , (
% (
8;
9 %
+ )
% :# ;
% 7< , =
# > 87%
9
2
:< , (
% (
# ;
"
, - $ . / - , (0 /
9
2
:% , (
% (
8;
9 %
+ )
% :# ;
% 7< , =
# > 87%
9
2
:< , (
% (
# ;
"
% 7< , = 87% > 8
9
1, $ 2
, 2
/
9 %
+ )
3 "
" ?
" 4
2 " !
%4
)
$
% *
AtomicStampedReference
set(V
newReference, int
newStamp)
get(stampHolder)
compareAndSet(expectedRef,
newRef,expectedStamp,newStamp)
" !&
"
" "
!%
!
8@(
) " A)
% :# ;
% 7< , =
# > 87%
9
2
:< , (
% (
# ;
"
, - $ . / - , (0 /
9
2
:% , (
% (
8;
9 %
:" *B
A; "
() *
"
5
, " %
" $
1
3
" , ) ) **
%
!"
'( $ )
2 , " *
" ,
&
0
" "
"
2 !!" ) **
" 7*
"
"
*% ,
!!
" *
1
3
% C