A detailed description of the programs, processes, and threads in Java ...

Source: Internet
Author: User

Program: A static code, a set of ordered sets of instructions, which itself does not have any meaning of running, it is just a static entity, is the application of software implementation of the blueprint.

process: is a dynamic execution of a program, which corresponds to loading from code, execution to completion of a complete process, is a dynamic entity, it has its own life

cycle. It is created because it is scheduled to run, is waiting for a resource or event, and is undone due to completion of the task. Reflects a program in

a certain amount of data all dynamic processes running on the set. A process is uniquely identified by a Process control block (PCB). While the process occupies the appropriate resources (such as a package

CPU-enabled with , the rotation time, and the permissions of some other devices). is a system for resource allocation and scheduling of an independent unit.

The main differences between programs and processes are:

Whether the state has a resource whether it has a unique identity and whether it has concurrency

Process Dynamic There are there are

Program Static No No No

Threads: can be understood as a number of execution threads for a process, each of which corresponds to its own independent life cycle. A thread is an entity of a process that is CPU-dispatched and dispatched

Basic unit, which is a smaller unit that can run independently than a process. One thread can create and revoke another thread, multiple threads in the same process

Room can and implementation.

Here is a detailed explanation of the concepts of processes and threads in Java.

Threads in Java go through 4 processes

1) Create

There are two common ways to create a Java thread:

Inherit the thread class and implement the Runnable interface in two ways.

2) execution

after a thread is created, it only occupies memory resources, and the thread does not yet have it in the JVM-managed thread, which must call the Start method to notify the JVM, so the JVM

would have know that there is another thread waiting in line. If the current thread is CPU-bound, the current thread will continue to execute.

3) Interrupt

A.JVM switches the use of the CPU from the current thread to another thread, leaving this thread out of the CPU's usage rights and in a broken state.

B. The thread calls the sleep method during execution, leaving the current thread in hibernation.

C. The thread calls the wait method during execution

D. A thread performs an action while it is using CPU resources in such a blocking state.

4) Death

The thread of death is not capable of execution. There are two causes of thread death:

A. Death caused by the end of the thread's normal operation, that is, the Run method is executed.

B. The thread was prematurely forced to terminate.

A detailed description of the programs, processes, and threads in Java ...

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.