Runnable and Thread in Java

Source: Internet
Author: User
Tags thread class

There are two ways to implement multithreading in Java: One is to inherit the thread class, and the other is to implement the Runnable interface.

1.java Why does the start thread use the start function?

Under the JDK installation path, Src.zip is the entire Java source program, and this code finds the definition of the start () method in thread, and you can see that the private native void Start0 () is used in this method;

Where the Native keyword means that the underlying function of the operating system can be called, then such a technique becomes a JNI technology (Java Native Interface).

2. Contact and difference:

The thread class, which has a constructor method: Public Thread (Runnable Targer) This construction method takes a subclass instance of Runnable, which means that the thread class is used to start the multithreading of the Runnable implementation. (Start () to coordinate the resources of the system).

In the program development of multithreading to implement Runnable interface, because the implementation of runnable interface compared to inherit the thread class, to avoid the limitations of inheritance, a class can implement multiple interfaces.

Runnable and Thread in Java

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.