Your SlideShare is downloading. ×
0
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
ぐだ生 Java入門第ニ回(synchronized and lock)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

ぐだ生 Java入門第ニ回(synchronized and lock)

1,244

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,244
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \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
  • Transcript

    • 1. JavaThread 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. synchronizedclass 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. • (by Wikipedia)• Java 1 1 1 1
    • 11. • • synchronized • Object#wait()• • synchronized • Object#wait()
    • 12. • synchronized•
    • 13. synchronizedclass Sample { public synchronized void execute1() { // } public void execute1b() { synchronized (this) { // } } public static synchronized void execute2() { // } public static synchronized void execute2b() { synchronized (Sample.class) { // } }}
    • 14. •
    • 15. •
    • 16. • Java VM • ••
    • 17. 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;}
    • 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; 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; }
    • 19. volatile
    • 20. volatile•• volatile• volatile
    • 21. volatileprivate 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;}
    • 22. Lock
    • 23. Lock• synchronized • lock() // synchronized • tryLock() // • tryLock(long,TimeUnit) // • lockInterruptibly() //
    • 24. • • try - finally Lock l = ...; l.lock(); try { // } finally { l.unlock(); }
    • 25. 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();}
    • 26. Lock• lock() synchronized• unlock() synchronized• Lock
    • 27. java.util.concurrent
    • 28. ...• wait() notify()/notifyAll() ( )•
    • 29. java.util.concurrent• Javadoc of java.util.concurrent • ExecutorService • • • • ConcurrentCollections •
    • 30. • synchronized• Java 17.4 Memory Model• java.util.concurrent• Java • Doug Lea ISBN:4-7973-3720-6

    ×