SlideShare una empresa de Scribd logo
1 de 15
Practical Concurrency January, 2009 http://javadom.blogspot.com/2011/06/lecture-on-java-concurrency-day-3.html
Day 3 (9am, Feb 11, 2009) Worker Thread Models Some Sample Codes Case Study Package java.util.concurrent
Worker Thread Models (1) ,[object Object],Master Worker Worker Worker Task Request Task Task Request Request
Worker Thread Models (2) ,[object Object],Prepare (Divide) Part Job 1 Part Job 2 Part Job 3 Time Progress Merge
Worker Thread Models (3) ,[object Object],Task 1 Step 1 Task 2 Step 1 Task 3 Step 1 Time Progress Task 1 Step 2 Task 2 Step 2 Task 3 Step 2 Task 1 Step 3 Task 2 Step 3 Task 3 Step 3 Task 1 Task 2 Task 3 Step 1 Thread Step 2 Thread Step 3 Thread Completed In Progress Before Start Legend
Sample : volatile on busy wait ,[object Object],[object Object],T1 T2 T1 T2 Call 1 Call 2 Call 3 Time Behavior of size 3 Barrier T3 T3
Sample : volatile on busy wait (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sample : long-lived object in worker ,[object Object],[object Object],[object Object]
Case : Collection Cache In Workers ,[object Object],[object Object],[object Object]
java.util.concurrent
History of java.util.concurrent ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrent Data Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Queue interface ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrency Artifacts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Executor & Future ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente (20)

Java 8 new features
Java 8 new features Java 8 new features
Java 8 new features
 
Introduction to Multithreading in Java
Introduction to Multithreading in JavaIntroduction to Multithreading in Java
Introduction to Multithreading in Java
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Preview of Groovy 3
Preview of Groovy 3Preview of Groovy 3
Preview of Groovy 3
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead Programming
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Multi-Threading
Multi-ThreadingMulti-Threading
Multi-Threading
 
Java thread life cycle
Java thread life cycleJava thread life cycle
Java thread life cycle
 
Thread
ThreadThread
Thread
 
Java threads
Java threadsJava threads
Java threads
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Java Multithreading
Java MultithreadingJava Multithreading
Java Multithreading
 
Java multi thread programming on cmp system
Java multi thread programming on cmp systemJava multi thread programming on cmp system
Java multi thread programming on cmp system
 
Java threads
Java threadsJava threads
Java threads
 
Multi-threaded Programming in JAVA
Multi-threaded Programming in JAVAMulti-threaded Programming in JAVA
Multi-threaded Programming in JAVA
 
Thread Dump Analysis
Thread Dump AnalysisThread Dump Analysis
Thread Dump Analysis
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34
 
Threading in C#
Threading in C#Threading in C#
Threading in C#
 

Destacado

Programming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptProgramming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptJoe Kutner
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Abhishek Khune
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Ralf Laemmel
 
Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)choksheak
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 

Destacado (14)

Threads
ThreadsThreads
Threads
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Week0 introduction
Week0 introductionWeek0 introduction
Week0 introduction
 
Binary trees
Binary treesBinary trees
Binary trees
 
Programming JVM Bytecode with Jitescript
Programming JVM Bytecode with JitescriptProgramming JVM Bytecode with Jitescript
Programming JVM Bytecode with Jitescript
 
Threads
ThreadsThreads
Threads
 
Sorting
SortingSorting
Sorting
 
Shared memory
Shared memoryShared memory
Shared memory
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)Multithreaded programming (as part of the the PTT lecture)
Multithreaded programming (as part of the the PTT lecture)
 
07 java collection
07 java collection07 java collection
07 java collection
 
Java Notes
Java NotesJava Notes
Java Notes
 
Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 

Similar a Lecture on Java Concurrency Day 3 on Feb 11, 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.
Lecture on Java Concurrency Day 2 on Feb 4, 2009.Kyung Koo Yoon
 
Java Multithreading and Concurrency
Java Multithreading and ConcurrencyJava Multithreading and Concurrency
Java Multithreading and ConcurrencyRajesh Ananda Kumar
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in androidRakesh Jha
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJAX London
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101Tim Penhey
 
Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfKrystian Zybała
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptxTREXSHyNE
 
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.pdfjexp
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrencykshanth2101
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyAnton Keks
 
Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performanceRoger Xia
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1Viên Mai
 

Similar a Lecture on Java Concurrency Day 3 on Feb 11, 2009. (20)

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.
 
Java Multithreading and Concurrency
Java Multithreading and ConcurrencyJava Multithreading and Concurrency
Java Multithreading and Concurrency
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Project Loom
Project LoomProject Loom
Project Loom
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
Here comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdfHere comes the Loom - Ya!vaConf.pdf
Here comes the Loom - Ya!vaConf.pdf
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptx
 
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
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrency
 
Internet Programming with Java
Internet Programming with JavaInternet Programming with Java
Internet Programming with Java
 
Java
JavaJava
Java
 
Java Course 10: Threads and Concurrency
Java Course 10: Threads and ConcurrencyJava Course 10: Threads and Concurrency
Java Course 10: Threads and Concurrency
 
Threading in java - a pragmatic primer
Threading in java - a pragmatic primerThreading in java - a pragmatic primer
Threading in java - a pragmatic primer
 
Java tips
Java tipsJava tips
Java tips
 
Java programing considering performance
Java programing considering performanceJava programing considering performance
Java programing considering performance
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Slide 7 Thread-1.pptx
Slide 7 Thread-1.pptxSlide 7 Thread-1.pptx
Slide 7 Thread-1.pptx
 
Slot02 concurrency1
Slot02 concurrency1Slot02 concurrency1
Slot02 concurrency1
 

Más de 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 ContainerKyung Koo Yoon
 
Smart software engineer
Smart software engineerSmart software engineer
Smart software engineerKyung 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
 

Más de Kyung Koo Yoon (12)

Kubernetes
Kubernetes Kubernetes
Kubernetes
 
Java 8 고급 (6/6)
Java 8 고급 (6/6)Java 8 고급 (6/6)
Java 8 고급 (6/6)
 
Java 8 고급 (5/6)
Java 8 고급 (5/6)Java 8 고급 (5/6)
Java 8 고급 (5/6)
 
Java 8 고급 (4/6)
Java 8 고급 (4/6)Java 8 고급 (4/6)
Java 8 고급 (4/6)
 
Java 8 고급 (3/6)
Java 8 고급 (3/6)Java 8 고급 (3/6)
Java 8 고급 (3/6)
 
Java 8 고급 (2/6)
Java 8 고급 (2/6)Java 8 고급 (2/6)
Java 8 고급 (2/6)
 
Java 8 고급 (1/6)
Java 8 고급 (1/6)Java 8 고급 (1/6)
Java 8 고급 (1/6)
 
Spring Framework - Inversion of Control Container
Spring Framework - Inversion of Control ContainerSpring Framework - Inversion of Control Container
Spring Framework - Inversion of Control Container
 
Smart software engineer
Smart software engineerSmart software engineer
Smart software engineer
 
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.
 
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.
 
창의와 열정, 소프트웨어 엔지니어
창의와 열정, 소프트웨어 엔지니어창의와 열정, 소프트웨어 엔지니어
창의와 열정, 소프트웨어 엔지니어
 

Último

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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 Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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 2024The 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
 
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 Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Lecture on Java Concurrency Day 3 on Feb 11, 2009.

Notas del editor

  1. Barrier.java public class Barrier { /* * count 와 reset 필드는 busy wait 을 할 때 체크되므로 , 다른 쓰레드가 * 값을 변경한 것이 항상 반영되도록 하기 위해서는 volatile 로 선언해야 한다 . */ private volatile int count; // sync 까지 남은 쓰레드 개수 private volatile boolean reset; // reset 상태인지 여부 private int resetCount; // sync 할 총 쓰레드 개수 private int waiters; // wait 상태의 쓰레드 개수 public Barrier(int count) { this.count = count; resetCount = count; reset = true; waiters = 0; } public void sync() { /* * sync() 루틴을 완료한 쓰레드들 중 아직 Barrier 가 reset 되기 전에 * 다시 sync() 루틴으로 들어온 경우에는 * 마지막으로 깨어난 쓰레드가 Barrier 를 reset 할 때까지 기다려야 한다 . * 이 경우에는 별도의 wait/notify 를 사용하기보다는 * 잠깐동안 busy wait 을 한다 . */ if (!reset && count == 0) { int loop = 0; // busy wait 하는 횟수를 보기 위한 디버깅 변수 while (true) { /* * 일찍 깨어난 쓰레드들은 CPU 를 양보하면서 reset 되길 기다리게 구현할 수도 있다 . * 이때 context switch 되므로 volatile 을 사용할 필요가 없다 . */ // Thread.yield(); // 메시지를 출력하기 위해 별도로 체크하였다 . // 메시지 출력이 필요없으면 loop 변수를 없애고 밖의 if 문을 while 문으로 바꾸면 된다 . if (reset || count != 0) { // reset 과 count 가 동기화 블록 밖에서 busy wait 하면서 체크되므로 volatile 로 선언되어야 한다 . System.out.println(Thread.currentThread().getName() + " end busy waiting after " + loop + " loops."); break; } loop++; } } synchronized (this) { // Barrier 객체에 대해서 동기화 count--; // Barrier 에 들어온 마지막 쓰레드인 경우 // 기다리던 모든 쓰레드들을 깨운다 . if (count == 0) { reset = false; // waking up all waiters System.out.println(Thread.currentThread().getName() + " is the last thread and waking up all waiters..."); notifyAll(); return; } // Barrier 에 들어온 쓰레드들 중 마지막이 아닌 쓰레드들은 // 모두 마지막 쓰레드가 깨워줄 때까지 기다린다 . while (count != 0) { ++waiters; System.out.println(Thread.currentThread().getName() + " waiting"); try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } --waiters; } // 기다리던 쓰레드들 중 마지막으로 깨어난 쓰레드는 // 모두 깨어나서 다음을 실행하도록 Barrier 를 reset 한다 . if (waiters == 0) { System.out.println(Thread.currentThread().getName() + " resets the barrier ..."); count = resetCount; // count 값을 초기화 reset = true; } } // end of synchronized (this) } }
  2. BarrierTest.java public class BarrierTest { private static final int NUM_THREADS = 5; // 방벽 구조를 사용하여 동기화할 쓰레드 개수 public static void main(String[] args) { Thread[] threads = new Thread[NUM_THREADS]; Barrier barrier = new Barrier(NUM_THREADS); // 쓰레드 갯수 크기의 Barrier 를 생성한다 // 테스트 쓰레드 생성 for (int i = 0; i < NUM_THREADS; i++) { threads[i] = new TestThread(i, barrier); } // 각 쓰레드를 실행한다 . for (int i = 0; i < NUM_THREADS; i++) { threads[i].start(); } // 모든 쓰레드가 종료할 때까지 기다린다 . for (int i = 0; i < NUM_THREADS; i++) { try { threads[i].join(); } catch (InterruptedException e) { e.printStackTrace(); } } } } /** * 방벽 구조를 테스트하는 쓰레드 */ class TestThread extends Thread { private static final int SYNC_COUNT = 3; // 방벽을 사용하여 동기화할 횟수 private Barrier barrier = null; TestThread(int id, Barrier barrier) { super("test-" + id); // 쓰레드 이름 지정 this.barrier = barrier; } public void run() { for (int i = 0; i < SYNC_COUNT; i++) { System.out.println(getName() + " before syncing " + i + "th time."); barrier.sync(); System.out.println(getName() + " after syncing " + i + "th time."); } } }
  3. WrongServlet.java import java.io.*; import javax.servlet.http.*; public class WrongServlet extends HttpServlet { private ServletConfig config; // OK! private HttpServletRequest request; // WRONG!!! public void init(ServletConfig config) throws ServletException { super.init(config); this.config = config; } public void doPut(HttpServletRequest req, HttpServletResponse res) { this.request = req; // WRONG!!! // ... } }
  4. Queue : Producer-Consumer pattern. One shared work queue among all the consumers Deque : double ended queue, Work stealing pattern. A consumer can steal work from the tail of someone else ’ s deque if he exhausts his work usually in a situation when the consumers are also producers. Annoying ConcurrentModificationException!!!
  5. boolean add(java.lang.Object e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. java.lang.Object element() throws NoSuchElementException Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty. boolean offer(java.lang.Object e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add(java.lang.Object) , which can fail to insert an element only by throwing an exception. java.lang.Object peek() Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. java.lang.Object poll() Retrieves and removes the head of this queue, or returns null if this queue is empty. java.lang.Object remove() throws NoSuchElementException Retrieves and removes the head of this queue. This method differs from poll only in that it throws an exception if this queue is empty. is empty.
  6. CountDownLatch CountDownLatch 클래스는 CyclicBarrier 클래스와 유사하게 해당 객체에 대해 await() 메쏘드를 호출하면 조건이 충족될 때까지 블로킹되지만 CyclicBarrier 가 await() 를 호출한 쓰레드의 갯수에 따라 블로킹을 풀어주는 반면 , CountDownLatch 는 countDown() 메쏘드가 호출되는 횟수에 따라 블로킹을 풀어주게 된다는 점이 다르다 . 또 CyclicBarrier 객체는 reset() 메쏘드를 제공해 다시 사용할 수 있지만 CountDownLatch 객체는 한번만 사용할 수 있다 . [ 래치 ( 회로 )( 어떤 입력에 대한 출력 상태를 다른 입력이 있을 때까지 유지하는 논리 회로 ).] 세마포어 세마포어는 내부적으로 숫자 값을 유지하고 있는데 이 값은 얼마든지 커질 수 있지만 0 보다 작을 수는 없다 . 세마포어는 acquire 와 release 두 개의 연산을 지원하며 , acquire 시에는 숫자 값을 1 감소시키고 , release 시에는 숫자 값을 1 증가시키되 숫자 값이 0 이 되면 acquire 를 요청한 쓰레드가 무한히 기다리도록 하는 방식으로 동작한다 . 이렇게 함으로써 결과적으로 동시에 접근하는 쓰레드의 갯수를 지정한 숫자 값으로 제한하게 된다 . Barrier 방벽 구조 (Barrier) 는 여러 쓰레드가 서로의 수행을 동기화하기 위해 기다리는 동기화 지점을 나타내는 구조이다 . 서로 협업하는 쓰레드들이 모두 방벽 지점에 이를 때까지 기다렸다가 모두 도착하면 다음 단계로 넘어가는 방식으로 진행된다 . 즉 , 마지막 쓰레드가 방벽 지점에 도착할 때까지 먼저 온 쓰레드는 기다리고 있다가 도착하는 순간 모두 다시 진행을 계속한다 . 즉 , 일정 개수의 쓰레드가 도달할 때까지 방벽이 각 쓰레드의 진행을 막고 있다가 일정 개수의 쓰레드가 도달하는 순간 도달한 쓰레드를 모두 방벽을 지나가도록 통과시키는 구조이다 . 이 구조는 선원 모델 (work crew model 혹은 divide and conquer model) 을 구현하는 데 많이 사용된다 . 선원 모델에서는 하나의 작업을 여러 조각의 부분 작업으로 나누어 여러 개의 쓰레드가 한 조각씩 동시에 수행하는 방식으로 작업을 수행한다 . 각 쓰레드는 다른 쓰레드의 작업 진행 상태에 의존하지 않고 독자적으로 작업을 진행한다 . 선원 모델의 예는 어떤 영역에 걸쳐 자료를 검색하는 작업이 있을 때 영역을 분리하여 각 영역별로 선원 쓰레드를 만들어 검색하는 것을 생각해볼 수 있다 . 각 부분 영역을 맡고 있는 쓰레드들이 모두 작업을 완료하면 부분 작업 결과들을 통합하여 전체 작업 결과가 나온다 . 일반적으로 선원 모델을 사용할 경우 각 선원 쓰레드별로 종료 시간이 다르므로 모든 선원 쓰레드가 종료한 후 각 결과물들을 종합하는 방식으로 진행하게 된다 . CyclicBarrier 클래스는 방벽 구조를 잘 구현한 클래스로 도달한 각 쓰레드는 CyclicBarrier 객체의 await() 메쏘드를 호출하고 지정된 정원이 찰 때까지 블로킹된다 . 정원이 차고 난 다음에는 CyclicBarrier 객체를 생성할 때 Runnable 객체가 지정한 경우 이 객체를 실행하여 결과물들을 종합하는 개념의 일을 할 수 있다 . CyclicBarrier 객체는 이 Runnable 을 수행한 후 블로킹됐던 모든 쓰레드를 풀어준다 . Exchanger Exchanger 클래스는 두 개의 쓰레드가 특정 지점에서 동일한 자료형의 데이터를 서로 교환할 수 있는 특별한 동기화 구조이다 . 두 개의 쓰레드가 동일한 Exchanger 객체에 대해 exchange() 메쏘드를 호출하면 두 쓰레드가 모두 호출할 때까지 블로킹되었다가 서로의 값을 교환한 후 계속해서 쓰레드가 진행하게 된다 .
  7. Executor 인터페이스는 쓰레드를 실행시키는 새로운 방법을 정의하고 있다 . Thread 클래스의 start() 메쏘드를 호출하는 대신 좀더 직관적으로 Runnable 을 실행시키거나 Callable 을 실행시킨다 . Callable 은 Runnable 과 유사하나 리턴값을 가질 수 있으며 예외를 던질 수 있다 . Interface Executor { void execute(Runnable runnable); } interface Callable<V> { V call() throws Exception; } interface ThreadFactory { Thread newThread(Runnable r); } Future 인터페이스는 비동기적으로 쓰레드를 수행하고 다른 일을 수행한 후 , 나중에 그 결과 값을 가져올 수 있는 구조이다 . Executor 와 Future 사용 예제 public static void main(String[] args) throws Exception { FutureTask<String> future = new FutureTask<String>(new Callable<String>() { public String call() throws IOException { … ( 생략 ) // 뭔가 복잡한 일을 한다 . return "Done"; } }); ExecutorService executor = Executors.newSingleThreadExecutor(); for (int i = 0; i < 3; i++) { // future 를 실행한다 . executor.execute(future); // 여기에서 다른 일을 먼저 수행한다 . Thread.sleep(1000L); // future 에 담긴 결과를 가져온다 . 아직 future 의 실행이 종료되지 않은 경우 블럭된다 . System.out.println("Callable returned : " + future.get()); } // executor 서비스를 종료한다 . executor.shutdown(); }