Java Multithreading (two)

Source: Internet
Author: User

I. Java Multithreading Mode 2: Implementing the Runnable Interface

  Benefit: A. Can avoid limitations due to Java single inheritance.

B. Suitable for multiple same program code to deal with the same resource situation, the thread and program code, data effectively separated, better reflect the object-oriented thinking. (e.g. multi-window ticketing)

1. Steps:

A. Custom class implementation interfaces

B. Overriding the Run () method

C. Creating the class instance

D. Create an object of the thread class, passing in the object created by C as a construction parameter

  Note: The way to implement the Runnable interface cannot use the thread class method, which can be used indirectly. such as get the name of the thread: Thread.CurrentThread (). GetName ()

E. Starting a Thread object

2. Comparison of two different ways

  

3. Ticketing examples

See the next article.

Java Multithreading (two)

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.