Java Interview Basics Summary (ii)---multithreading

Source: Internet
Author: User
Tags thread class
1. Three ways to realize multithreading

1. Follow the thread class and cover the Run () method to

2.implements runnable Interface

3.implements Callale interface, execute with Futuretask to start thread

2, Thread synchronization method

Synchronized, lock

3, ThreadLocal

When you use threadlocal to maintain a variable, threadlocal provides a separate copy of the variable for each variable that uses the thread, so that each thread can operate its own copy of the variable independently.

There are four methods of threadlocal<t>:

void set (T value), setting the value of the thread local variable for the current thread

Public T GET, which returns the value of the copy of the variable that corresponds to the current thread

Remove from public void to delete the variable copy of the current thread

Protected TT Initalvalue (), returns the initial value of the copy of the thread variable. The first call to get or set on a thread executes only once.

Not to be continued ...

Java Interview Basics Summary (ii)---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.