Java thread (1): Concepts and Principles

Source: Internet
Author: User

SCJP5 learning Notes 1. Concept of operating system midline and process the current operating system is a multi-task operating system. Multithreading is a way to implement multiple tasks. A process is an application running in the memory. Each process has its own memory space. A process can start multiple threads. For example, in Windows, a running exe is a process. A thread is an execution process in a process. A process can run multiple threads. For example, a java. EXE process can run multiple threads. A thread always belongs to a process. multiple threads in the process share the memory of the process. "At the same time" execution is a human perception, and is actually rotated between threads. 2. in Java, "Threads" refer to two different things: 1. an instance of the Java. lang. Thread class; 2. Thread execution. Use the java. lang. Thread class or java. lang. Runnable interface to write code to define, instantiate, and start a new Thread. A Thread class instance is just an object. Like any other object in Java, it has variables and methods, and is born and died on the heap. In Java, each thread has a call stack. Even if no new thread is created in the program, the thread runs in the background. A Java application always runs from the main () method, and the mian () method runs in a thread, which is called the main thread. Once a new thread is created, a new call stack is generated. Threads are divided into two types: User thread and waiting thread. When all user threads are executed, the JVM automatically closes. However, the waiting thread is not independent from the JVM. The waiting thread is generally created by the operating system or the user.

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.