Goals for JSR 166 The concurrency improvements in Tiger should: Make some problems trivial to solve by everyone Make some problems easier to solve by concurrent programmers Make some problems possible to solve by concurrency experts
2022-2-27 Institute of Computer Software Nanjing University 11
Background for JSR 166 Based mainly on package EDU.oswego.cs.dl.util.concurrent from http://gee.cs.oswego.edu by Doug Lea APls refactored based on 4+years of usage experience -APIs enhanced to use generics,enumerations Implementations improved to take advantage of -Additional native JVM constructs -New Java Memory Model guarantees(JSR 133)
2022-2-27 Institute of Computer Software Nanjing University 12
What's new in Tiger for Concurrency? New classes and enhancements Executors,Thread Pools,and Futures Concurrent collections:Queues,Blocking Queues,ConcurrentHashMap ·Locks and Conditions Synchronizers:Semaphores,Barriers,etc. ·Atomic Variables Low-level compare-and-set operation ·Other enhancements -Nanosecond-granularity timing
2022-2-27 Institute of Computer Software Nanjing University 13
&扇 Thread Pool 102 14 Server applications... Thread-per-request approach... Single-background-thread approach... Thread pool offers a solution to both the problem of thread life-cycle overhead and the problem of resource thrashing. Institute of Computer Software 2022-2-27 Nanjing University
Thread Pool Server applications… Thread-per-request approach… Single-background-thread approach… Thread pool offers a solution to both the problem of thread life-cycle overhead and the problem of resource thrashing. 2022-2-27 Institute of Computer Software Nanjing University 14
Risks of using thread pools 15 Deadlock all pool threads are executing tasks that are blocked waiting for the results of another task on the queue,but the other task cannot run because there is no unoccupied thread available Resource thrashing Thread pool size should be tuned properly. ▣Concurrency errors Thread leakage occurs when a thread is removed from the pool to perform a task, but is not returned to the pool when the task completes. Request overload Institute of Computer Software 2022-2-27 Nanjing University
Risks of using thread pools Deadlock all pool threads are executing tasks that are blocked waiting for the results of another task on the queue, but the other task cannot run because there is no unoccupied thread available Resource thrashing Thread pool size should be tuned properly. Concurrency errors Thread leakage occurs when a thread is removed from the pool to perform a task, but is not returned to the pool when the task completes. Request overload 2022-2-27 Institute of Computer Software Nanjing University 15