Soumettre la recherche
Mettre en ligne
ぐだ生 Java入門第ニ回(synchronized and lock)
•
Télécharger en tant que KEY, PDF
•
0 j'aime
•
831 vues
Makoto Yamazaki
Suivre
Technologie
Signaler
Partager
Signaler
Partager
1 sur 31
Télécharger maintenant
Recommandé
Java Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
Java Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
Effective java - concurrency
Effective java - concurrency
feng lee
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
Threads
Threads
Then Murugeshwari
Arc of developer part1
Arc of developer part1
Junpei Wada
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
Andrei Pangin
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
Roman Elizarov
Recommandé
Java Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
Java Concurrency Gotchas
Java Concurrency Gotchas
Alex Miller
Effective java - concurrency
Effective java - concurrency
feng lee
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Charles Nutter
Threads
Threads
Then Murugeshwari
Arc of developer part1
Arc of developer part1
Junpei Wada
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
Andrei Pangin
Wait for your fortune without Blocking!
Wait for your fortune without Blocking!
Roman Elizarov
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
CanSecWest
Migrating to JUnit 5
Migrating to JUnit 5
Rafael Winterhalter
Full solution to bounded buffer
Full solution to bounded buffer
Syed Zaid Irshad
Java Concurrency
Java Concurrency
Carol McDonald
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
Pavel Albitsky
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch
The Art of JVM Profiling
The Art of JVM Profiling
Andrei Pangin
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
Java 7 LavaJUG
Java 7 LavaJUG
julien.ponge
Java 5 concurrency
Java 5 concurrency
priyank09
C++ Advanced Features
C++ Advanced Features
Michael Redlich
C++ Advanced Features
C++ Advanced Features
Michael Redlich
concurrency_c#_public
concurrency_c#_public
Paul Churchward
Code generation for alternative languages
Code generation for alternative languages
Rafael Winterhalter
Java 7 at SoftShake 2011
Java 7 at SoftShake 2011
julien.ponge
Java 7 JUG Summer Camp
Java 7 JUG Summer Camp
julien.ponge
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
julien.ponge
076-600.pdf
076-600.pdf
unn | UNITED NEWS NETWORK GmbH
Flisol Uni 2009
Flisol Uni 2009
Henry
Successful Citizen Service - This Road's Built for You
Successful Citizen Service - This Road's Built for You
Pam Broviak
Contenu connexe
Tendances
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
CanSecWest
Migrating to JUnit 5
Migrating to JUnit 5
Rafael Winterhalter
Full solution to bounded buffer
Full solution to bounded buffer
Syed Zaid Irshad
Java Concurrency
Java Concurrency
Carol McDonald
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
Pavel Albitsky
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch
The Art of JVM Profiling
The Art of JVM Profiling
Andrei Pangin
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
Java 7 LavaJUG
Java 7 LavaJUG
julien.ponge
Java 5 concurrency
Java 5 concurrency
priyank09
C++ Advanced Features
C++ Advanced Features
Michael Redlich
C++ Advanced Features
C++ Advanced Features
Michael Redlich
concurrency_c#_public
concurrency_c#_public
Paul Churchward
Code generation for alternative languages
Code generation for alternative languages
Rafael Winterhalter
Java 7 at SoftShake 2011
Java 7 at SoftShake 2011
julien.ponge
Java 7 JUG Summer Camp
Java 7 JUG Summer Camp
julien.ponge
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
julien.ponge
Tendances
(19)
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
Migrating to JUnit 5
Migrating to JUnit 5
Full solution to bounded buffer
Full solution to bounded buffer
Java Concurrency
Java Concurrency
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
soft-shake.ch - Java SE 7: The Fork/Join Framework and Project Coin
The Art of JVM Profiling
The Art of JVM Profiling
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 LavaJUG
Java 7 LavaJUG
Java 5 concurrency
Java 5 concurrency
C++ Advanced Features
C++ Advanced Features
C++ Advanced Features
C++ Advanced Features
concurrency_c#_public
concurrency_c#_public
Code generation for alternative languages
Code generation for alternative languages
Java 7 at SoftShake 2011
Java 7 at SoftShake 2011
Java 7 JUG Summer Camp
Java 7 JUG Summer Camp
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
En vedette
076-600.pdf
076-600.pdf
unn | UNITED NEWS NETWORK GmbH
Flisol Uni 2009
Flisol Uni 2009
Henry
Successful Citizen Service - This Road's Built for You
Successful Citizen Service - This Road's Built for You
Pam Broviak
for Perl newbie
for Perl newbie
なんとか くら
孩子你慢慢来
孩子你慢慢来
Xiaochun Shen
Promoting best practice for early warning of landslides - Reclaim 3
Promoting best practice for early warning of landslides - Reclaim 3
Strengthening Climate Resilience
En vedette
(6)
076-600.pdf
076-600.pdf
Flisol Uni 2009
Flisol Uni 2009
Successful Citizen Service - This Road's Built for You
Successful Citizen Service - This Road's Built for You
for Perl newbie
for Perl newbie
孩子你慢慢来
孩子你慢慢来
Promoting best practice for early warning of landslides - Reclaim 3
Promoting best practice for early warning of landslides - Reclaim 3
Similaire à ぐだ生 Java入門第ニ回(synchronized and lock)
Java synchronizers
Java synchronizers
ts_v_murthy
Non blocking io with netty
Non blocking io with netty
Zauber
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Charles Nutter
.NET Multithreading and File I/O
.NET Multithreading and File I/O
Jussi Pohjolainen
Concurrency gotchas
Concurrency gotchas
Jitender Jain
Java concurrency begining
Java concurrency begining
maksym220889
Java concurrency
Java concurrency
Hithem Ahmed
Thread
Thread
phanleson
Concurrency in Programming Languages
Concurrency in Programming Languages
Yudong Li
Java Concurrency Idioms
Java Concurrency Idioms
Alex Miller
CSharp for Unity Day2
CSharp for Unity Day2
Duong Thanh
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
Carol McDonald
Real-Time Streaming with Apache Spark Streaming and Apache Storm
Real-Time Streaming with Apache Spark Streaming and Apache Storm
Davorin Vukelic
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
Artur Latoszewski
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Víctor Bolinches
Multithreading in Java
Multithreading in Java
Appsterdam Milan
Chapter v(error)
Chapter v(error)
Chhom Karath
Fork and join framework
Fork and join framework
Minh Tran
Javaoneconcurrencygotchas 090610192215 Phpapp02
Javaoneconcurrencygotchas 090610192215 Phpapp02
Tarun Kumar
Play image
Play image
Fardian Syah
Similaire à ぐだ生 Java入門第ニ回(synchronized and lock)
(20)
Java synchronizers
Java synchronizers
Non blocking io with netty
Non blocking io with netty
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
.NET Multithreading and File I/O
.NET Multithreading and File I/O
Concurrency gotchas
Concurrency gotchas
Java concurrency begining
Java concurrency begining
Java concurrency
Java concurrency
Thread
Thread
Concurrency in Programming Languages
Concurrency in Programming Languages
Java Concurrency Idioms
Java Concurrency Idioms
CSharp for Unity Day2
CSharp for Unity Day2
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
Real-Time Streaming with Apache Spark Streaming and Apache Storm
Real-Time Streaming with Apache Spark Streaming and Apache Storm
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Multithreading in Java
Multithreading in Java
Chapter v(error)
Chapter v(error)
Fork and join framework
Fork and join framework
Javaoneconcurrencygotchas 090610192215 Phpapp02
Javaoneconcurrencygotchas 090610192215 Phpapp02
Play image
Play image
Plus de Makoto Yamazaki
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
Makoto Yamazaki
Custom lintcheckをつくろう
Custom lintcheckをつくろう
Makoto Yamazaki
20120516 第7回ウフィカ社内ハンズオン Git基礎
20120516 第7回ウフィカ社内ハンズオン Git基礎
Makoto Yamazaki
ICS ホットトピック
ICS ホットトピック
Makoto Yamazaki
DevQuiz 2011 の模範解答 Android編
DevQuiz 2011 の模範解答 Android編
Makoto Yamazaki
USB Host APIで遊んでみた
USB Host APIで遊んでみた
Makoto Yamazaki
20110619 live view ideathon_logcatonliveview
20110619 live view ideathon_logcatonliveview
Makoto Yamazaki
I/O 2011 報告会 ADKで遊んでみた
I/O 2011 報告会 ADKで遊んでみた
Makoto Yamazaki
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
Makoto Yamazaki
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
Makoto Yamazaki
ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)
Makoto Yamazaki
20110326 ネットプリントの紹介
20110326 ネットプリントの紹介
Makoto Yamazaki
20110109 abc2010w gingerbread_api_storage
20110109 abc2010w gingerbread_api_storage
Makoto Yamazaki
Plus de Makoto Yamazaki
(13)
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
20150425 DroidKaigi つかえるGradleプロジェクトの作り方
Custom lintcheckをつくろう
Custom lintcheckをつくろう
20120516 第7回ウフィカ社内ハンズオン Git基礎
20120516 第7回ウフィカ社内ハンズオン Git基礎
ICS ホットトピック
ICS ホットトピック
DevQuiz 2011 の模範解答 Android編
DevQuiz 2011 の模範解答 Android編
USB Host APIで遊んでみた
USB Host APIで遊んでみた
20110619 live view ideathon_logcatonliveview
20110619 live view ideathon_logcatonliveview
I/O 2011 報告会 ADKで遊んでみた
I/O 2011 報告会 ADKで遊んでみた
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第三回(文字コードの話)(Keynote版)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第一回(equals hash code_tostring)
ぐだ生 Java入門第一回(equals hash code_tostring)
20110326 ネットプリントの紹介
20110326 ネットプリントの紹介
20110109 abc2010w gingerbread_api_storage
20110109 abc2010w gingerbread_api_storage
Dernier
presentation ICT roal in 21st century education
presentation ICT roal in 21st century education
jfdjdjcjdnsjd
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
apidays
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
UK Journal
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Khem
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Roshan Dwivedi
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
lior mazor
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Principled Technologies
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
wesley chun
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
wesley chun
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
The Digital Insurer
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Andrey Devyatkin
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Martijn de Jong
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
The Digital Insurer
Dernier
(20)
presentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
ぐだ生 Java入門第ニ回(synchronized and lock)
1.
Java Thread
2011 4 9 twitter: @zaki50
2.
Who am I •
YAMAZAKI Makoto(twitter: @zaki50) • Android • • StickyShortcut • Java
3.
• Effective Java
2 • ISBN:978-4-89471-499-1 • 3,780 ( ) • 66, 69
4.
Agenda • synchronized /
volatile • Lock(ReentrantLock) • java.util.concurrent
5.
synchronized
6.
Eclipse
(jvisualvm)
7.
synchronized class Sample {
public synchronized void execute1() { // } public void execute1b() { synchronized (this) { // } } public static synchronized void execute2() { // } public static synchronized void execute2b() { synchronized (Sample.class) { // } } }
8.
synchronized • • •
9.
•
10.
11.
•
(by Wikipedia) • Java 1 1 1 1
12.
•
• synchronized • Object#wait() • • synchronized • Object#wait()
13.
•
synchronized •
14.
synchronized class Sample {
public synchronized void execute1() { // } public void execute1b() { synchronized (this) { // } } public static synchronized void execute2() { // } public static synchronized void execute2b() { synchronized (Sample.class) { // } } }
15.
•
16.
•
17.
• Java VM
• • •
18.
private static boolean
stopRequested = false; private static int value = 0; public static void main(String[] args) throws Exception { new Thread() { @Override public void run() { int i = 0; if (!stopRequested) { while (!stopRequested) { while (true) { i++; i++; } } } System.out.println(value); } }.start(); TimeUnit.SECONDS.sleep(1L); value = 100; stopRequested = true; }
19.
private static boolean
stopRequested = false; private static int value = 0; public static void main(String[] args) throws Exception { new Thread() { @Override public void run() { int i = 0; while (!stopped()) { i++; } System.out.println(value); } }.start(); private synchronized static void stop() { stopRequested = true; TimeUnit.SECONDS.sleep(1L); } value = 100; stop(); private synchronized static boolean stopped() { } return stopRequested; }
20.
volatile
21.
volatile • • volatile • volatile
22.
volatile private volatile static
boolean stopRequested = false; private volatile static int value = 0; public static void main(String[] args) throws Exception { new Thread() { @Override public void run() { int i = 0; while (!stopRequested) { i++; } System.out.println(value); } }.start(); TimeUnit.SECONDS.sleep(1L); value = 100; stopRequested = true; }
23.
Lock
24.
Lock • synchronized •
lock() // synchronized • tryLock() // • tryLock(long,TimeUnit) // • lockInterruptibly() //
25.
•
• try - finally Lock l = ...; l.lock(); try { // } finally { l.unlock(); }
26.
ReentrantReadWriteLock rwLock =
new ReentrantReadWriteLock(); Lock wl = rwLock.writeLock(); Lock rl; wl.lock(); try { // write rl = rwLock.readLock(); } finally { wl.unlock(); } try { // read } finally { rl.unlock(); }
27.
Lock • lock()
synchronized • unlock() synchronized • Lock
28.
java.util.concurrent
29.
... • wait()
notify()/notifyAll() ( ) •
30.
java.util.concurrent •
Javadoc of java.util.concurrent • ExecutorService • • • • ConcurrentCollections •
31.
• synchronized • Java
17.4 Memory Model • java.util.concurrent • Java • Doug Lea ISBN:4-7973-3720-6
Notes de l'éditeur
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Télécharger maintenant