Home » Java » A Java based concurrent programming

A Java based concurrent programming

1, synchronous and asynchronous

invocation of synchronous and asynchronous description methods.

Synchronization: once the method call starts, the caller must wait until the method call returns to continue the subsequent behavior. The serial method calls.

Asynchronous method calls are more like a message passing, which returns.

immediately when the method calls
2, concurrency and parallelism

Concurrency: multiple tasks alternate execution.

Parallel: on multiple CPU systems, multiple CPU perform tasks simultaneously,.


3, critical zone:

is used to represent common or common data. It can be used by multiple threads simultaneously, but each time only one thread can use it. Code or resources that can be shared.


4, blocking and non blocking

is used to describe the interaction between multiple threads.

A thread occupies the critical area resource, then all other threads that need this resource must wait in this critical area. Waiting for the thread to hang up is blocked by.


means non blocking, and it emphasizes that no thread can prevent other threads from executing. All threads will try to keep moving forward,.


5, hunger, deadlock, livelock

is a multi threading activity issue.

A deadlock caused by resource contention or communication between two or more threads of two or more.


starvation, one or more threads, cannot obtain the required resources for various reasons, resulting in the failure to execute.


two tasks without blocking livelock, but when you get the resources to each other, "humility" and could not have execution conditions. Because some conditions are not met, has led to repeated attempts, failure, failure to try.


6, concurrent level:

concurrency levels can be divided into the following categories: blocking, starvation free, barrier free, no locking, no waiting,.


block: a thread is blocked and the current thread cannot execute until the other thread releases the resource.

No hunger: between threads is a priority, then thread scheduling, always tend to meet the high priority thread. If the lock is fair, meet in order of arrival will not happen. So the hungry, blocking some threads cannot be executed without hunger is all of the threads can be executed, congestion will produce hunger.


accessibility, is a non blocking operation is the weakest. If two threads are accessible, so they will not be because of the critical region problem that a party has been suspended. In other words, everyone can come swaggeringly to enter the critical section. If modifying together to share data, the data of the bad how to do? For non barrier threads, once detected this situation, he would roll back.

on its own modifications immediately

lock: lock free parallel are no obstacles. In no lock case, all threads will attempt to access the critical region, but the difference is that lock free concurrent threads to ensure ratio must have left the operation to complete critical.

in finite steps

no wait: requires all threads to complete.

within a limited step
7, atomicity, visibility, order

atomicity: refers to an operation that is not interrupted. Even when multiple threads are executed together, an operation will not be disturbed by other threads once the case is.


The

ordering program may perform instruction rearrangement when executed, and the reordering order is not necessarily consistent with the order of the original instruction.


visibility when a thread modifies the value of a shared variable, other threads can immediately know the modification.


8, the Happen-Before principle:

program sequence principle: to ensure semantic serialization in a thread.


volatile rule: the writing of the volatile variable takes place first in the read, which guarantees the visibility of the Volatie variable.


lock rule: Unlock must occur before subsequent lock


transitivity: A precedes B, and B precedes C, then A must precede C.


The start method of the

thread precedes each of its actions.


All operations on the

thread precede the end of the thread.

The thread's interrupt precedes the code
of the broken thread
The constructor of the object executes and ends before the finalize method

Latest