"DAY8" Learning notes on multithreading

Source: Internet
Author: User

Jar Packaging

---------------

Jar CVF xxx.jar-c classes/.

Process

-----------------

Memory-isolated between processes. Memory is not shared.

Thread

-----------------

A code snippet that executes concurrently during the execution of a program.

Memory can be shared between threads.


Thread: Threading class.

Start ()//Notifies the CPU that the thread can start executing.

Run () //thread specifically executes the code snippet.

Thread t = new thread ();

T.start ();

Thread.CurrentThread ()//Gets the current execution thread.

Yield ()//Let the thread discard the CPU preemption.

Sleep (int mils)//lets the current thread hibernate for the specified number of milliseconds.


Thread safety: Added synchronous processing. Make sure that only one thread executes the synchronization code at the same time.

The synchronization method uses the current object as the synchronization object.

Static methods can be processed synchronously, using class as the synchronization object.

Methods in multi-threading

-----------------------

Yield ()//Let the thread discard the CPU preemption. Humility.

Join ()// main thread waits for the termination of the child thread

Sleep (int ms); /lets the current thread hibernate for the specified number of milliseconds.

Setdaemon (TRUE); //thread pre-boot settings

Isdaemon (); //Specifies whether the thread is daemon thread daemon

Start (); //Start thread

Run (); //thread-specific code snippet execution

Notify ()//Select a monitor object to wait for a thread in the queue to be notified.

Notifyall ()//Select all monitor objects to wait for a thread in the queue to be notified.

Wait ()//puts the current thread in the monitor's wait queue.

Wait (int n)//thread enters wait queue, waits up to n long time, once, automatically wakes up.

TIPS: Call the Sleep () method to catch the exception.


This article is from the "Yehomlab" blog, make sure to keep this source http://yehom.blog.51cto.com/5159116/1784242

"DAY8" Learning notes on multithreading

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.