Java Multithreading Basics

Source: Internet
Author: User

Wait and notify are for sychronized locked objects.
Sychronized (object) object.wait ();//Release the lock of object
Sychronized (object) object.notify ();//will randomly evoke a waiting thread on the object yoke, the process is randomly awakened, unfair
Sychronized (object) Object.notifyall ()//will wake up all threads that lock on object

Suspend (thread hang) and resume (continue)

Suspend the lock is not released after the thread is suspended until the resume operation;

If the resume is executed before suspend, then the thread is hard to wake up, and the thread or runable from the threading point of view will always affect the system.

If optimization suspend need to be implemented with wait and notify

Join and yield

Join means waiting for thread to end execution again

Yield indicates humility, which means that the current thread gives up the CPU and lets other threads work.

Addthread at=new Addthrea ();

At.start ();

At.join ();

Indicates that the current thread is blocked, waiting for the at thread to complete before executing the current thread

Join (Millis) means that if it is not executed after waiting for Millis, it will go directly to execute

Java Multithreading 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.