Basic Concepts && Lifecycle of Java threads

Source: Internet
Author: User
(i) Basic concepts of threads:


(1) Processes and Threads:
Process: Running applications are called processes, owning system resources (CPU, memory)
Thread: A piece of code in a process that can have more than one piece of code in a process. does not own resources (shares the resources of the process in which it resides)


(2) Distinguishing between processes and threads:
1. The question of whether or not to occupy resources
2. The overhead required to create or undo a process is greater than the overhead required to create or undo a thread.
3, the process is a heavyweight component, the thread is a lightweight component


(3) Multiple threads and multiple processes:
Multi-process: multiple tasks (Programs) can be run at the same time in the operating system.
Multithreading: Multiple function flows are executed simultaneously in the same application.


(4) The purpose of the thread:
①, use it to do repetitive work (such as animation, sound playback).
②, engaged in one-time more time-consuming initialization work (such as network connectivity, sound data file loading).
③, concurrent execution of a running effect (multiple threads of a process) for more complex functionality.


(5) The advantages of multithreading:
① can reduce the bottleneck of system performance, because it can be operated in parallel;
②, to improve the efficiency of CPU processor, in multiple threads, through the priority management, can make important program priority operation, improve the flexibility of task management; On the other hand, in a multi-CPU system, different threads can be executed in different CPUs, and multitasking is really handled simultaneously.


(6) The main characteristics of the thread:
1) can not be in a file name independent of the existence of the disk;
2) can not be carried out alone, only after the process has started to start;
3 The thread can share the same memory (code and data) of the process.


(7) The priority of the thread:
Each Java thread has a priority, which helps the operating system determine the scheduling order of the threads. The Java priority is within the range of min_priority (1) and max_priority (10). By default, each thread assigns a priority norm_priority (5).


(ii) Life cycle/state transition diagram for Java threads:




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: [email protected] 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.