Big Data-java Foundation -9day

Source: Internet
Author: User

How threads are Created

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

1. Inherit the Thread class.

2. Implement the Runnable interface.

1), create a thread through the thread class, and pass the class object that implements the Runnable interface as a parameter to the constructor of the thread class. The thread class called the start () method to start the thread.

3. The thread calls the Start method and does not execute immediately, but is in a ready state, waiting for the CPU to execute.

4. Thread security issues.


Thread synchronization

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

1. Thread synchronization: Synchronized (object) {.. Code blocks that need to be synchronized ...}. The object here is an object of any class. The object is like the function of a lock.

2. Prerequisites for Thread synchronization:

1) synchronization requires two or more threads.

2) Multiple threads using the same lock

3. Synchronization will reduce the efficiency of the program operation. So the code in sync is as short as possible.

4. The synchronization method uses the lock of the object on which the method resides.

Thread Wait (wait)

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

1. After the thread calls wait, the thread frees the CPU and waits, and after the CPU is acquired again, the code executes from wait.

Priority of the thread

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

1.setPriority (); Set the priority of a thread

2.getPriority (); Gets the priority of the thread

3. High-priority CPU gain is a bit more likely.

Thread state transition diagram

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

650) this.width=650; "src=" http://note.youdao.com/yws/res/211/502D74341A9E4DD69C0813D76A3A6924 "style=" margin-top : 8px;height:566.737px;width:800px; "alt=" 502d74341a9e4dd69c0813d76a3a6924 "/>

Strng

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

1. "= =" is to determine whether the memory address of two string objects is equal

2. "Equal" is to determine whether the contents of two string objects are equal

3.StringBuffer is thread-safe. Low efficiency. StringBuilder is a class that is later added and is thread insecure and highly efficient.

4. Unpacking and boxing of basic data types.


Big Data-java Foundation -9day

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: 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.