Threads and Package Util.Concurrent research (1) 1. Introduction: Writing scheduling and concurrent infrastructure classes are really difficult than look. The Java language provides a group of useful low-level synchronization primates: Wait (), notify () and synchronized, but specific use of these primitives require some techniques, you need to consider performance, deadlock, fairness, resource management, and how to avoid thread safety Many factors such as hazards caused by sex. The concurrent code is difficult to write, more difficult to test - even if the experts are sometimes in the first time, there will be errors. Concurrent Programming in Java (see
Reference
Author Doug Lea, written an extremely excellent, free concurrent utility package, including concurrent applications lock, mutually exclusive, queue, thread pool, lightweight task, effective concurrent collection, atom's arithmetic operation and Other basic components. It is generally called Util.Concurrent (because it is actually packaged), the package will form the basis of Java Community Process JSR 166 is standardizing JAVA.UTIL.CONCURRENT package. At the same time, Util.Concurrent has been tested, and many server applications (including JBoss J2EE application servers) use this package.
2. Design goals: translation from http://gee.cs.oswego.edu/dl/cpjslides/UTIL.PDF
1). Provide some simple ease of use: Although the coverage has reached most programmed requirements, sometimes you need to write some code yourself.
2). High quality implementation: correct, tradition, effective, portable.
3). Provide foundation for future standardization: experience and collect feedback.
3. Structure:
The implementation of class interface attached subclass is generally divided into three parts: SYNC, CHANNEL, Executor.
The structure of this package is followed by the following hierarchy: atomic-> sync-> channel-> executor. Atomic: Aiming at an atomic operation CAS (CompareAndswtich) for various objects. Sync: All kinds of locking mechanisms for thread synchronization based on ATOMIC - mutex, signal lights, etc. Channel: Use the lock mechanism provided by SYNC to implement various task queues - block queues, linked table queues, priority queues, etc. Executor: Provides a variety of thread management methods - thread pools, etc. These management methods are implemented based on the task queue provided by CHANNEL. 4. Executor and other classes of relationship: Each section will be described in detail in the later chapter.