Java support for the management process, Java Management Process

Source: Internet
Author: User

Java support for the management process, Java Management Process

Concept of management process

 

A process (Moniters, also known as a monitor) is a program structure. Multiple working threads in the structure form multiple subprograms (objects or modules) to access shared resources. These shared resources are generally hardware devices or a group of variables. At a time point, only one thread can execute a subprogram of a management process. Compared with the concurrent program design that implements mutex access by modifying the data structure, the management process greatly simplifies the program design. A mechanism is provided for a thread to temporarily discard mutex access. After some conditions are met, the thread obtains the execution right again to restore its mutex access.

A process includes:

Before running a thread, a program of a pipe process acquires a mutex lock until the thread is completed or the thread waits for a condition to be met before giving up the mutex lock. If every thread in the execution can ensure that the invariant is true before giving up the mutex lock, then all threads will not cause the race condition to be true. When a thread executes a child program in a pipe program, it is called occupy. The implementation of the pipe process ensures that at one point in time, only one thread occupies the tube. This is the mutex lock access nature of the management process. When a thread needs to call a subroutine defined in a pipe program, it must wait until there is no other thread in the execution of a subroutine. In the simple implementation of a pipe program, the compiler automatically adds a private mutex lock to each pipe object. The initial status of the mutex lock is unlocked. The mutex lock is locked at the entrance of each public subroutine of the tube process and unlocked at the exit of each public subroutine of the tube process.

Conditional Variable)

It provides a simple way to achieve mutual exclusion, but this is not enough. We also need a way to block the thread when it cannot continue running. In the producer-consumer issue, it is easy to put the test for buffer full and buffer empty into the pipe process. But how can the producer block when the buffer is found to be full? The solution is to introduce conditional variables and related two operations: wait and signal. When a pipe process finds that it cannot continue running (for example, the producer finds that the buffer is full), it will perform the wait operation on a certain condition variable (such as full. This operation causes the calling process to be blocked and calls another process that was previously outside the management process to the management process. Another thread, such as a consumer, can wake up a sleeping partner process, which can be completed by executing signal on a condition variable that the partner is waiting. To avoid two active processes in the same process, if several processes are waiting on a condition variable, after performing the signal operation on the condition variable, the system scheduler can only select one of them to resume running.

The thread may need to wait for a condition P to be true to continue execution. In a busy waiting loop, while not (P) do skip will cause all other processes to fail to enter the critical section to make the condition P true, causing a deadlock on the pipe. the solution is conditional variables ). in concept, a condition variable is a queue, where the thread is waiting for a condition to become true. Each condition variable c is associated with an asserted P_c. when a thread waits for a condition variable, the thread does not count as occupying the thread. Therefore, other threads can enter the thread for execution and change the status of the thread, the asserted P_c associated with the notification condition variable c is true in the current state.

Therefore, there are two main operations on the condition variable: wait c is called by a thread to resume execution after the asserted P_c is satisfied. when the thread hangs on the condition variable and waits, it is not considered to be occupying the pipe. signal c (sometimes writing notify c) is called by a thread to assert that P_c is now true. when a notification (signal) sends a conditional variable with a thread in the waiting state, at least two threads will occupy the thread: the thread sending the notification and the thread waiting for the notification. only one thread occupies this pipe, so you must make a choice. The two theoretical systems lead to the implementation of two different conditional variables: Blocking condition variables, which gives priority to the notified thread. nonblocking condition variables gives priority to the notification thread.

Implicit Conditional Variable

In Java programming language, each object can be used as a pipe program. The synchronized keyword must be explicitly identified for mutually exclusive use. the code block can also indicate the keyword synchronized. the explicit condition variables are not used. Java programs use separate conditions to wait for the queue outside the entry queue. all the waiting threads enter this queue, and all the Y and notify all operations are also applied to this queue. This method has been used by other programming languages, such as C #.

The synchronization method in Java is essentially different from other classical processes: Java does not have nested conditional variables. On the contrary, Java provides two processes: wait AND ipvy, which are equivalent to sleep and wakeup. However, when they are used in synchronous methods, they are not subject to competition conditions. Theoretically, wait can be interrupted, and it is the Code related to the interruption. Java needs to explicitly indicate exception handling.

 

Java enterprise-level general permission security framework source code SpringMVC mybatis or hibernate + ehcache shiro druid bootstrap HTML5

 

[Download java framework source code]

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.