SlideShare a Scribd company logo
Java 나흘째
TmaxSoft R&D Center
1
113년	 10월	 15일	 화
자바 교육 계획
1일 : Language, String,
ClassLoader, Proxy
2일 : GC, Collections
3일 : Thread, Java Memory
Model
4일 : AQS, ForkJoin,
Concurrent Utils
5일 : IO, Generics, Annotation,
RMI
6일 : Unsafe, Lambda (Java 8)
2
213년	 10월	 15일	 화
오늘 내용
Hotspot JVM Locking Optimization Review
java.util.concurrent
Atomic CAS
AbstractQueueSynchronizer, Lock & Condition
Concurrent Collections
Fork-Join framework
3
313년	 10월	 15일	 화
지난 시간 리뷰 :
Hotspot JVM Lock Optimization
volatile (JMM)
park/unpark
4
413년	 10월	 15일	 화
Locking
Lightweight locking
Atomic CAS
Heavyweight locking
mutex
Using the assumption that most locking is
uncontended
try lightweight first and if failed then use heavyweight
5
513년	 10월	 15일	 화
Mark word (Object Header)
2bits are used for lock state
01 : unlocked
00 : light-weight locked
10 : heavy-weight locked
11 : marked for GC
1 more bit is used for biased locking (obtained via CAS)
X01 : unlocked
X is 0 for not biased, X is 1 for biased or biasable
2bit epoch is used for indicate the bias-holding thread’s lock/unlock
6
Hashcode Age 0 01
lock record address 00
monitor address 10
forward address, etc.. 11
thread id Age 1 01epoch
613년	 10월	 15일	 화
Biased Locking
(quickly reacquirable lock)
make it cheap for a single thread to re-acquire the same
lock
when biased bit is 1
when the biased thread locks/unlocks
word에서 thread id 만을 검사하고 epoch bit 변경
when other thread locks
revoke (expensive) : 먼저 light-weight lock 상태로 되돌린
다
7
713년	 10월	 15일	 화
volatile
단순한 메모리 변수가 아니라 barrier를 필요로 함
thread가 접근한 변수들의 visibility와 ordering 모두 만족해야
x86 등에서 실제 구현 형태
보통 volatile field에 set 후에 StoreLoad(x86에서는 mfence
등에 해당)를 호출하는 것으로 구현
CPU마다 다르긴 하나 x86, SPARC에서는 다른 instrunction
은 모두 no-op
8
813년	 10월	 15일	 화
park/unpark 모델 (JDK 5)
9
Park Unpark
Parked
Unparked
None
Impossible None
None Unparked
Parked Unparked
현재 상태
Operation
[표] 현재 상태 + Operation => 다음 상태
park/unpark는 biased를 사용하지 않으므로 thread간 lock 경
쟁이 심할 경우 synchronized에 비해 더 효율적
synchronized는 single thread이거나 contention이 약하면 더
효율적
913년	 10월	 15일	 화
java.util.concurrent (JDK 5)
10
1013년	 10월	 15일	 화
Atomic CAS
11
package java.util.concurrent.atomic
e.g, AtomicInteger
volatile value
compareAndSet : cpu dependent instruction
other methods : set, getAndIncrement, ...
while loop (spin lock) and CAS
1113년	 10월	 15일	 화
AbstractQueuedSynchronizer (1)
package java.util.concurrent.locks
a small common framework of most provided synchronizers
acquire : blocks the calling thread unless/until the synchronization
state allows it to proceed
release : changes synchronization state in a way that may allow
one or more blocked threads to unblock
tryAcquire/tryRelease : non-blocking version (child class should
implement if necessary)
acquireShared/releaseShared : shared mode
12
1213년	 10월	 15일	 화
AbstractQueuedSynchronizer (2)
acquire operation
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;
release operation
update synchronization state;
if (state may permit a blocked thread to acquire)
unblock one or more queued threads;
13
1313년	 10월	 15일	 화
AbstractQueuedSynchronizer (3)
int synchronization state (32bit)
blocking
LockSupport.park
LockSupport.unpark(Thread)
FIFO wait queue of blocked threads (CLH queue)
Condition queue of blocked threads
class AbstractQueuedSynchronizer.ConditionObject
14
1413년	 10월	 15일	 화
AbstractQueuedSynchronizer (4)
class Mutex {
class Sync extends AbstractQueuedSynchronizer {
public boolean tryAcquire(int ignore) {
return compareAndSetState(0, 1); // locked 이면 state == 1
}
public boolean tryRelease(int ignore) {
setState(0); return true; // unlocked 이면 state == 0
}
}
private final Sync sync = new Sync();
public void lock() { sync.acquire(0); }
public void unlock() { sync.release(0); }
}
15
1513년	 10월	 15일	 화
AbstractQueuedSynchronizer (5)
ReentrantLock (and Condition) : state is recursive lock count
ReentrantReadWriteLock : state 16bit writer count, 16bit reader count
Semaphore : state is current count, acquire calls acquireShared to
decrement or block (if <= 0), release calls releaseShared to increment
and unblock (if > 0)
CountDownLatch : state is count, countDown calls releaseShared
(decrements 1), await calls acquireShared (if state is 0, return
immediately)
FutureTask : state is state machine (initial|running|cancelled|done). set/
cancel calls release which eventually unblock the awaiting threads which
are trying to acquire to get the value
16
1613년	 10월	 15일	 화
Lock overhead
Measured in JDK 5
(So, builtin is not
meaningful)
17
1713년	 10월	 15일	 화
ThreadPoolExecutor
Core pool size, Max pool size, blocking queue size
java.util.concurrent.Executors helper class
newFixedThreadPool (Core pool size == max pool size)
newCachedThreadPool
Core pool size = 0, Max pool size = Integer.MAX_VALUE,
SynchronousQueue
newSingleThreadExecutor (Unbounded queue)
newScheduledThreadPool (Can execute by schedule)
18
1813년	 10월	 15일	 화
Fork/Join (JDK 7)
a parallel version of divide-conquer algorithm
Result solve(Problem problem) {
if (problem is small)
directly solve problem
else {
split problem into independent parts
fork new subtasks to solve each part
join all subtasks
compose result from subresults
}
}
19
1913년	 10월	 15일	 화
Fork/Join
work-stealing
deque : array, top, base
push/pop/take(steal)
owner thread : stack(LIFO) push/pop
idle thread : take and if fail then yield or set inactive
20
base top
deque
push
pop
steal (thread 2)
(thread 1)
2013년	 10월	 15일	 화
Fork/Join
ForkJoinTask methods
child classes should override exec(), setRawResult(), getRawResult()
public static void invokeAll(ForkJoinTask<?> t1, ForkJoinTask<?> t2) {
t2.fork();
t1.invoke();
t2.join();
}
ForkJoinPool : can specify parallelism (thread pool size)
RecursiveAction (result가 없는 ForkJoinTask)
RecursiveTask (result가 있는 ForkJoinTask)
21
2113년	 10월	 15일	 화
Concurrent Collections
CopyOnWriteArrayList : read-mostly, high contention
LinkedBlockingQueue : 2-lock queue algorithm
separation of takeLock and putLock
ConcurrentHashMap
lock striping
no lock when get (multiple access to volatile data)
ConcurrentSkipListMap
concurrent version of skip-list
a concurrent replacement for TreeMap
22
2213년	 10월	 15일	 화
다음 시간 예정
some more concurrent collections
Generics
Annotation
I/O
Object Serialization
RMI
23
2313년	 10월	 15일	 화
Ad

More Related Content

What's hot (20)

Non-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need itNon-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need it
Alexey Fyodorov
 
Disruptor
DisruptorDisruptor
Disruptor
Larry Nung
 
Heap & thread dump
Heap & thread dumpHeap & thread dump
Heap & thread dump
Nishit Charania
 
Thanos - Prometheus on Scale
Thanos - Prometheus on ScaleThanos - Prometheus on Scale
Thanos - Prometheus on Scale
Bartłomiej Płotka
 
Barcamp presentation
Barcamp presentationBarcamp presentation
Barcamp presentation
Vachagan Balayan
 
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
GOG.com dev team
 
Lock free programming- pro tips
Lock free programming- pro tipsLock free programming- pro tips
Lock free programming- pro tips
Jean-Philippe BEMPEL
 
Mq light in microservices
Mq light in microservicesMq light in microservices
Mq light in microservices
Steve Upton
 
Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...
Jimmy Lai
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
Terry Cho
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
feng lee
 
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
Ontico
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
JAX London
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++
Dimitrios Platis
 
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudyスローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
Yusuke Yamamoto
 
FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!
Vincent Claes
 
Percona XtraDB 集群内部
Percona XtraDB 集群内部Percona XtraDB 集群内部
Percona XtraDB 集群内部
YUCHENG HU
 
Distributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevdayDistributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevday
odnoklassniki.ru
 
Yet another introduction to Linux RCU
Yet another introduction to Linux RCUYet another introduction to Linux RCU
Yet another introduction to Linux RCU
Viller Hsiao
 
Non-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need itNon-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need it
Alexey Fyodorov
 
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
GOG.com dev team
 
Mq light in microservices
Mq light in microservicesMq light in microservices
Mq light in microservices
Steve Upton
 
Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...
Jimmy Lai
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
Terry Cho
 
Effective java - concurrency
Effective java - concurrencyEffective java - concurrency
Effective java - concurrency
feng lee
 
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
pg / shardman: шардинг в PostgreSQL на основе postgres / fdw, pg / pathman и ...
Ontico
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
JAX London
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++
Dimitrios Platis
 
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudyスローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
スローダウン、ハングを一発解決 スレッドダンプはトラブルシューティングの味方 #wlstudy
Yusuke Yamamoto
 
FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!
Vincent Claes
 
Percona XtraDB 集群内部
Percona XtraDB 集群内部Percona XtraDB 集群内部
Percona XtraDB 集群内部
YUCHENG HU
 
Distributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevdayDistributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevday
odnoklassniki.ru
 
Yet another introduction to Linux RCU
Yet another introduction to Linux RCUYet another introduction to Linux RCU
Yet another introduction to Linux RCU
Viller Hsiao
 

Similar to Java 8 고급 (4/6) (20)

Java 8 고급 (6/6)
Java 8 고급 (6/6)Java 8 고급 (6/6)
Java 8 고급 (6/6)
Kyung Koo Yoon
 
Java concurrency introduction
Java concurrency introductionJava concurrency introduction
Java concurrency introduction
yangwm
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
Roman Elizarov
 
Java tips
Java tipsJava tips
Java tips
Viswanath Lekshmanan
 
Threading in java - a pragmatic primer
Threading in java - a pragmatic primerThreading in java - a pragmatic primer
Threading in java - a pragmatic primer
SivaRamaSundar Devasubramaniam
 
Concurrency in Java
Concurrency in  JavaConcurrency in  Java
Concurrency in Java
Allan Huang
 
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance TuningProfiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
osa_ora
 
Thread & concurrancy
Thread & concurrancyThread & concurrancy
Thread & concurrancy
Onkar Deshpande
 
Introduction+To+Java+Concurrency
Introduction+To+Java+ConcurrencyIntroduction+To+Java+Concurrency
Introduction+To+Java+Concurrency
King's College London
 
Project Coin
Project CoinProject Coin
Project Coin
Balamurugan Soundararajan
 
Java Multithreading and Concurrency
Java Multithreading and ConcurrencyJava Multithreading and Concurrency
Java Multithreading and Concurrency
Rajesh Ananda Kumar
 
CS844 U1 Individual Project
CS844 U1 Individual ProjectCS844 U1 Individual Project
CS844 U1 Individual Project
ThienSi Le
 
Memory model
Memory modelMemory model
Memory model
Yi-Hsiu Hsu
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
jexp
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrent
Roger Xia
 
Java synchronizers
Java synchronizersJava synchronizers
Java synchronizers
ts_v_murthy
 
Reliable and Concurrent Software - Java language
Reliable and Concurrent Software - Java languageReliable and Concurrent Software - Java language
Reliable and Concurrent Software - Java language
ssuser2637a1
 
Hs java open_party
Hs java open_partyHs java open_party
Hs java open_party
Open Party
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data Structures
Dilum Bandara
 
Concurrency Learning From Jdk Source
Concurrency Learning From Jdk SourceConcurrency Learning From Jdk Source
Concurrency Learning From Jdk Source
Kaniska Mandal
 
Java concurrency introduction
Java concurrency introductionJava concurrency introduction
Java concurrency introduction
yangwm
 
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
Roman Elizarov
 
Concurrency in Java
Concurrency in  JavaConcurrency in  Java
Concurrency in Java
Allan Huang
 
Profiler Guided Java Performance Tuning
Profiler Guided Java Performance TuningProfiler Guided Java Performance Tuning
Profiler Guided Java Performance Tuning
osa_ora
 
Java Multithreading and Concurrency
Java Multithreading and ConcurrencyJava Multithreading and Concurrency
Java Multithreading and Concurrency
Rajesh Ananda Kumar
 
CS844 U1 Individual Project
CS844 U1 Individual ProjectCS844 U1 Individual Project
CS844 U1 Individual Project
ThienSi Le
 
Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
jexp
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrent
Roger Xia
 
Java synchronizers
Java synchronizersJava synchronizers
Java synchronizers
ts_v_murthy
 
Reliable and Concurrent Software - Java language
Reliable and Concurrent Software - Java languageReliable and Concurrent Software - Java language
Reliable and Concurrent Software - Java language
ssuser2637a1
 
Hs java open_party
Hs java open_partyHs java open_party
Hs java open_party
Open Party
 
Introduction to Concurrent Data Structures
Introduction to Concurrent Data StructuresIntroduction to Concurrent Data Structures
Introduction to Concurrent Data Structures
Dilum Bandara
 
Concurrency Learning From Jdk Source
Concurrency Learning From Jdk SourceConcurrency Learning From Jdk Source
Concurrency Learning From Jdk Source
Kaniska Mandal
 
Ad

More from Kyung Koo Yoon (12)

Kubernetes
Kubernetes Kubernetes
Kubernetes
Kyung Koo Yoon
 
Java 8 고급 (5/6)
Java 8 고급 (5/6)Java 8 고급 (5/6)
Java 8 고급 (5/6)
Kyung Koo Yoon
 
Java 8 고급 (3/6)
Java 8 고급 (3/6)Java 8 고급 (3/6)
Java 8 고급 (3/6)
Kyung Koo Yoon
 
Java 8 고급 (2/6)
Java 8 고급 (2/6)Java 8 고급 (2/6)
Java 8 고급 (2/6)
Kyung Koo Yoon
 
Java 8 고급 (1/6)
Java 8 고급 (1/6)Java 8 고급 (1/6)
Java 8 고급 (1/6)
Kyung Koo Yoon
 
Spring Framework - Inversion of Control Container
Spring Framework - Inversion of Control ContainerSpring Framework - Inversion of Control Container
Spring Framework - Inversion of Control Container
Kyung Koo Yoon
 
Smart software engineer
Smart software engineerSmart software engineer
Smart software engineer
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Lecture on Java Concurrency Day 3 on Feb 11, 2009.Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Lecture on Java Concurrency Day 2 on Feb 4, 2009.Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Lecture on Java Concurrency Day 4 on Feb 18, 2009.Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 1 on Jan 21, 2009.
Lecture on Java Concurrency Day 1 on Jan 21, 2009.Lecture on Java Concurrency Day 1 on Jan 21, 2009.
Lecture on Java Concurrency Day 1 on Jan 21, 2009.
Kyung Koo Yoon
 
창의와 열정, 소프트웨어 엔지니어
창의와 열정, 소프트웨어 엔지니어창의와 열정, 소프트웨어 엔지니어
창의와 열정, 소프트웨어 엔지니어
Kyung Koo Yoon
 
Spring Framework - Inversion of Control Container
Spring Framework - Inversion of Control ContainerSpring Framework - Inversion of Control Container
Spring Framework - Inversion of Control Container
Kyung Koo Yoon
 
Smart software engineer
Smart software engineerSmart software engineer
Smart software engineer
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Lecture on Java Concurrency Day 3 on Feb 11, 2009.Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Lecture on Java Concurrency Day 3 on Feb 11, 2009.
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Lecture on Java Concurrency Day 2 on Feb 4, 2009.Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Lecture on Java Concurrency Day 2 on Feb 4, 2009.
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Lecture on Java Concurrency Day 4 on Feb 18, 2009.Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Lecture on Java Concurrency Day 4 on Feb 18, 2009.
Kyung Koo Yoon
 
Lecture on Java Concurrency Day 1 on Jan 21, 2009.
Lecture on Java Concurrency Day 1 on Jan 21, 2009.Lecture on Java Concurrency Day 1 on Jan 21, 2009.
Lecture on Java Concurrency Day 1 on Jan 21, 2009.
Kyung Koo Yoon
 
창의와 열정, 소프트웨어 엔지니어
창의와 열정, 소프트웨어 엔지니어창의와 열정, 소프트웨어 엔지니어
창의와 열정, 소프트웨어 엔지니어
Kyung Koo Yoon
 
Ad

Recently uploaded (20)

FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 

Java 8 고급 (4/6)

  • 1. Java 나흘째 TmaxSoft R&D Center 1 113년 10월 15일 화
  • 2. 자바 교육 계획 1일 : Language, String, ClassLoader, Proxy 2일 : GC, Collections 3일 : Thread, Java Memory Model 4일 : AQS, ForkJoin, Concurrent Utils 5일 : IO, Generics, Annotation, RMI 6일 : Unsafe, Lambda (Java 8) 2 213년 10월 15일 화
  • 3. 오늘 내용 Hotspot JVM Locking Optimization Review java.util.concurrent Atomic CAS AbstractQueueSynchronizer, Lock & Condition Concurrent Collections Fork-Join framework 3 313년 10월 15일 화
  • 4. 지난 시간 리뷰 : Hotspot JVM Lock Optimization volatile (JMM) park/unpark 4 413년 10월 15일 화
  • 5. Locking Lightweight locking Atomic CAS Heavyweight locking mutex Using the assumption that most locking is uncontended try lightweight first and if failed then use heavyweight 5 513년 10월 15일 화
  • 6. Mark word (Object Header) 2bits are used for lock state 01 : unlocked 00 : light-weight locked 10 : heavy-weight locked 11 : marked for GC 1 more bit is used for biased locking (obtained via CAS) X01 : unlocked X is 0 for not biased, X is 1 for biased or biasable 2bit epoch is used for indicate the bias-holding thread’s lock/unlock 6 Hashcode Age 0 01 lock record address 00 monitor address 10 forward address, etc.. 11 thread id Age 1 01epoch 613년 10월 15일 화
  • 7. Biased Locking (quickly reacquirable lock) make it cheap for a single thread to re-acquire the same lock when biased bit is 1 when the biased thread locks/unlocks word에서 thread id 만을 검사하고 epoch bit 변경 when other thread locks revoke (expensive) : 먼저 light-weight lock 상태로 되돌린 다 7 713년 10월 15일 화
  • 8. volatile 단순한 메모리 변수가 아니라 barrier를 필요로 함 thread가 접근한 변수들의 visibility와 ordering 모두 만족해야 x86 등에서 실제 구현 형태 보통 volatile field에 set 후에 StoreLoad(x86에서는 mfence 등에 해당)를 호출하는 것으로 구현 CPU마다 다르긴 하나 x86, SPARC에서는 다른 instrunction 은 모두 no-op 8 813년 10월 15일 화
  • 9. park/unpark 모델 (JDK 5) 9 Park Unpark Parked Unparked None Impossible None None Unparked Parked Unparked 현재 상태 Operation [표] 현재 상태 + Operation => 다음 상태 park/unpark는 biased를 사용하지 않으므로 thread간 lock 경 쟁이 심할 경우 synchronized에 비해 더 효율적 synchronized는 single thread이거나 contention이 약하면 더 효율적 913년 10월 15일 화
  • 11. Atomic CAS 11 package java.util.concurrent.atomic e.g, AtomicInteger volatile value compareAndSet : cpu dependent instruction other methods : set, getAndIncrement, ... while loop (spin lock) and CAS 1113년 10월 15일 화
  • 12. AbstractQueuedSynchronizer (1) package java.util.concurrent.locks a small common framework of most provided synchronizers acquire : blocks the calling thread unless/until the synchronization state allows it to proceed release : changes synchronization state in a way that may allow one or more blocked threads to unblock tryAcquire/tryRelease : non-blocking version (child class should implement if necessary) acquireShared/releaseShared : shared mode 12 1213년 10월 15일 화
  • 13. AbstractQueuedSynchronizer (2) acquire operation 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; release operation update synchronization state; if (state may permit a blocked thread to acquire) unblock one or more queued threads; 13 1313년 10월 15일 화
  • 14. AbstractQueuedSynchronizer (3) int synchronization state (32bit) blocking LockSupport.park LockSupport.unpark(Thread) FIFO wait queue of blocked threads (CLH queue) Condition queue of blocked threads class AbstractQueuedSynchronizer.ConditionObject 14 1413년 10월 15일 화
  • 15. AbstractQueuedSynchronizer (4) class Mutex { class Sync extends AbstractQueuedSynchronizer { public boolean tryAcquire(int ignore) { return compareAndSetState(0, 1); // locked 이면 state == 1 } public boolean tryRelease(int ignore) { setState(0); return true; // unlocked 이면 state == 0 } } private final Sync sync = new Sync(); public void lock() { sync.acquire(0); } public void unlock() { sync.release(0); } } 15 1513년 10월 15일 화
  • 16. AbstractQueuedSynchronizer (5) ReentrantLock (and Condition) : state is recursive lock count ReentrantReadWriteLock : state 16bit writer count, 16bit reader count Semaphore : state is current count, acquire calls acquireShared to decrement or block (if <= 0), release calls releaseShared to increment and unblock (if > 0) CountDownLatch : state is count, countDown calls releaseShared (decrements 1), await calls acquireShared (if state is 0, return immediately) FutureTask : state is state machine (initial|running|cancelled|done). set/ cancel calls release which eventually unblock the awaiting threads which are trying to acquire to get the value 16 1613년 10월 15일 화
  • 17. Lock overhead Measured in JDK 5 (So, builtin is not meaningful) 17 1713년 10월 15일 화
  • 18. ThreadPoolExecutor Core pool size, Max pool size, blocking queue size java.util.concurrent.Executors helper class newFixedThreadPool (Core pool size == max pool size) newCachedThreadPool Core pool size = 0, Max pool size = Integer.MAX_VALUE, SynchronousQueue newSingleThreadExecutor (Unbounded queue) newScheduledThreadPool (Can execute by schedule) 18 1813년 10월 15일 화
  • 19. Fork/Join (JDK 7) a parallel version of divide-conquer algorithm Result solve(Problem problem) { if (problem is small) directly solve problem else { split problem into independent parts fork new subtasks to solve each part join all subtasks compose result from subresults } } 19 1913년 10월 15일 화
  • 20. Fork/Join work-stealing deque : array, top, base push/pop/take(steal) owner thread : stack(LIFO) push/pop idle thread : take and if fail then yield or set inactive 20 base top deque push pop steal (thread 2) (thread 1) 2013년 10월 15일 화
  • 21. Fork/Join ForkJoinTask methods child classes should override exec(), setRawResult(), getRawResult() public static void invokeAll(ForkJoinTask<?> t1, ForkJoinTask<?> t2) { t2.fork(); t1.invoke(); t2.join(); } ForkJoinPool : can specify parallelism (thread pool size) RecursiveAction (result가 없는 ForkJoinTask) RecursiveTask (result가 있는 ForkJoinTask) 21 2113년 10월 15일 화
  • 22. Concurrent Collections CopyOnWriteArrayList : read-mostly, high contention LinkedBlockingQueue : 2-lock queue algorithm separation of takeLock and putLock ConcurrentHashMap lock striping no lock when get (multiple access to volatile data) ConcurrentSkipListMap concurrent version of skip-list a concurrent replacement for TreeMap 22 2213년 10월 15일 화
  • 23. 다음 시간 예정 some more concurrent collections Generics Annotation I/O Object Serialization RMI 23 2313년 10월 15일 화