Java Multithreading Series--Basic concept of "basic article" 01

Source: Internet
Author: User
Tags sleep function

Multithreading is an unavoidable and important subject in Java. Starting with this chapter, we'll start learning about multithreading. What follows is a description of the Java multithreaded content before the "new Juc package in JDK", including the Wait (), notify () interface in the object class, the interface in the thread class, and the synchronized keyword.

Note: TheJuc package refers to the Java.util.concurrent package, which is completed by the Java Master Doug Lea and added to Java in the JDK1.5 version.


Before you go to the later chapters, learn some of the concepts related to multithreading.
Thread state diagram

Description
The thread altogether consists of the following 5 states.
1.new State (new): When the thread object is created, it enters the new state. For example, thread thread = new Thread ().
2.ready State (Runnable): Also known as an "executable state". When the thread object is created, the other thread invokes the object's start () method to start the thread. For example, Thread.Start (). A thread that is in a ready state may be executed by the CPU at any time.
3. Running State (Running) : Thread gets CPU permission to execute. It is important to note that a thread can only go from a ready state to a running state.
4. blocking State (Blocked) : The blocking state is a temporary stop for a thread that has abandoned the CPU usage for some reason. Until the thread is in a ready state, the opportunity to go to the running state is reached. There are three types of blocking:
wait for blocking--by calling the thread's Wait () method, to let the thread wait for a job to complete.
Synchronous blocking--the thread acquires a synchronized synchronization lock failure (because the lock is occupied by another thread) and it goes into a synchronous blocking state.
other blocking-the thread goes into a blocking state by calling the thread's sleep () or join () or making an I/O request. When the sleep () state times out, join () waits for the thread to terminate or time out, or the I/O process finishes, the thread is re-entered in a ready state.
5. death Status (Dead) : The thread finishes executing or exits the run () method because of an exception, and the thread ends the life cycle.

The 5 states involved include the object class, the thread, and the synchronized keyword. We'll learn about this in a later chapter.
The object class , which defines the sleep/wake functions such as Wait (), notify (), Notifyall ().
The thread class , which defines a number of column-manipulation functions. For example, the sleep () sleep function, the interrupt () interrupt function, GetName () Gets the thread name, and so on.
synchronized, which is a keyword, distinguishes it from synchronized code blocks and synchronized methods. The function of synchronized is to have the thread get the synchronization lock of the object.

Java Multithreading Series--Basic concept of "basic article" 01

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.