Java Core technology-Multi thread Basics

Source: Internet
Author: User
Tags thread class

Speaking of threads, it is not possible to mundane the first three concepts to be understood: process, thread, and association. OK, so what is a process, what is a thread, and which is what? Process: The process can be easily understood as running in the operating system of the program, the program static code, the process is the dynamic running code, the operation of the program needs to the operating system resources such as memory, file handle, and so on, especially emphasizes that the process request resources are independent, that is, the process and process resources are independent. It is dispatched by the operating system, so the process is relative to the operating system; Thread: The thread is the one in the process that executes the task, and it shares the resources that the process requests; it can simply be a lightweight thread made by threads. Finish the basic concept and look at the diagram before the three:

See from the diagram is not a glance. It is also important to emphasize that both the process and the thread are managed by the operating system kernel, and the threads are managed by the program, in the user state. Since the Java thread, the Java process has not heard of it, the Java language does not implement the association, the implementation of the language such as Python,go, if you want to use the coprocessor in Java, you can use the co-framework Kilim.

Finish the concept and go straight to the Java threading World. In Java threads can use the thread class to construct a thread object, yes, the new thread () is a thread object, and the new Date () is no different, is a Java object instance, is not very simple? The simplicity here refers to the simple construction, but after the introduction of the problem is not easy (later). We know that the object itself has a life cycle, the ordinary Java object is dead and live two life cycle state, and for the thread object there are new, ready, running, block or waitting, dead six states, state transition diagram:

The transition of the thread state is dependent on the JVM invoking the operating system kernel TCB, which is the thread control module, to implement thread state switching.

Now that the thread is an object in Java, what are the properties of this object? Thread properties can be divided into static and dynamic properties, static here refers to the programmer is immutable, there is a JVM allocation, dynamic refers to the programmer can be customized, although the JVM gave the default property values. Static attributes: ID, etc., Dynamic properties: Name,priority,deamon,group,classloader, etc. So much for the basics, that's what it's all about.

As can be seen from the above program, when we run the program, the equivalent of starting a JVM application in the operating system, that is, the process, and then the JVM calls the main method, the thread that executes the main method is the main course (that is, the process must have a portal thread-main thread, That is, at least one thread), and then the main thread initiates a child thread.

Well, the Java Threading Basics Introductory article describes this, and the next chapter continues the thread-based memory allocation knowledge of the thread base section. Special note, I have limited skills and knowledge, if there are errors, welcome friends to correct, thank you very much.

Java Core technology-Multi thread Basics

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.