java util concurrent

The first chapter multithreading and concurrency basics

Concurrent behind the question:

1.3 procedures, processes and threads

Program is a static concept, Windows usually refers to exe files.

The concept is a dynamic process, the state of the program is running, process instructions border program in memory.

A thread is a basic task in the process, each thread has its own function, is cpu basic unit of allocation and scheduling.

Three characteristics of the threads: atomicity, visibility, orderly

java memory model: JAVA Memory Model

 

Chapter java multithreading

2.1 create multi-threaded - inheritance Thread class

Three ways to create threads:

Inheritance Thread class implement Runnable interface to use Callable and Future create a thread

2.2 create multi-threaded - implement Runnable Interface

 

2.3 create multi-threaded - implement Callable Interface

 

2.4Synchronized thread synchronization mechanism

 

2.5 thread five states

New ready running blocked death

 

2.6 Deadlock generation

When the multi-threaded operation of public resources, not to release on his own resources, attempt to operate away resources from other threads, to form cross-references, will produce a deadlock.

Minimize public resources references, run out immediately released;

2.7 new understanding of thread-safe ThreadSafe

 

 

Chapter III JDK concurrency utilities package JUC

3.1java concurrent connection pooling Toolkit

executors

1.CachedThreadPool be cached thread pool

Infinity, if there is no available thread pool thread is created, there is a free thread is used up

2.FixedThreadPool fixed-length thread pool

The total number of fixed thread, the thread used to perform spatial tasks, if the threads are using the follow-up into a wait state, after the release of threads in the pool, then perform subsequent tasks.

If the task is in a wait state, waiting for an alternative algorithm LIFO LIFO

3.SingleThreadExcecutor single thread pool

4.ScheduledTreadPool scheduling thread pool

Thread pool Advantages:

Reuse existing threads, reducing the overhead of the object demise

Thread is always controllable, improve resource utilization

Avoid excessive competition for resources, avoid blocking

Provide additional functionality, timing of execution, periodic execution, monitoring, etc.

 

3.2JUC of CountDownLatch countdown lock

Total score for the task.

3.3JUC the Semaphore semaphore

Semaphore.acquire() semaphore.release() 

 

3.4JUC of CyclicBarrier circulation barrier

3.5JUC of ReetrantLook reentrant lock

After any thread to acquire a lock, to acquire the lock again and the lock will not be blocked.

3.6JUC of Condition thread waiting and wake

Core methods:

await () blocks the current thread until the signal wake

signal () wakes up the await thread to continue where it left off

signalAll () wake up all await () blocked thread

3.7JUCCallable_Future

Callable return a value and can throw an exception

Future is an interface that is used to represent the result of an asynchronous computation. It provides a way to check whether the calculation is completed, in order to wait for the completion of the calculation, and obtain the results of the calculation.

3.8JUC synchronize container

3.9JUCAtomicCAS算法

原子性:是指一个操作或者多个操作要么全部执行,且执行过程中不会被任何因素打断,要么都不执行。

3.10课程总结

Guess you like

Origin www.cnblogs.com/zszitman/p/11111703.html