Threading primer, talking about thread and runnable

Source: Internet
Author: User

One implementation of the Runnable interface uses a thread.


Here we implemented the interface with Runnabletest, created the object of the implementation class in the main function, and passed it to the

Thread's constructor, and then call the Start method. The code is as follows


public class Runnabletest implements Runnable {@Override public void run () {System.out.println (Thread.curren    TThread (). GetName () + "is Running");        } public static void Main (string[] args) {runnabletest run = new Runnabletest ();        Thread thread = new thread (run);    Thread.Start (); }}



Two inherited threads to use a thread


Again, we can inherit the thread class and rewrite his run () method to use threads.

public class ThreadTest extends Thread {@Override public void run () {System.out.println (Thread.currentthrea    D (). GetName () + "is Running");        } public static void Main (string[] args) {threadtest thread = new ThreadTest ();    Thread.Start (); }}
















This article is from the "11450029" blog, please be sure to keep this source http://11460029.blog.51cto.com/11450029/1763490

Threading primer, talking about thread and runnable

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.