Java thread Start (implement Runnable interface)

Source: Internet
Author: User

The procedure is as follows:

Class ThreadDemo1 implements runnable{//implements Runnable interface private string name;private int time;public ThreadDemo1 (String name , int time) {this.name=name;this.time=time;} public void Run () {//Overwrite the Run method try {thread.sleep (this.time)} catch (Interruptedexception e) {//TODO auto-generated catch bl Ocke.printstacktrace ();} System.out.println (this.name+ "thread hibernation" +this.time);}} public class MyThread {public static void main (string[] args) {ThreadDemo1 thread01=new ThreadDemo1 ("A", 1000);// Implement Runnable sub-class object; ThreadDemo1 thread02=new ThreadDemo1 ("B", 2000); ThreadDemo1 thread03=new ThreadDemo1 ("C", "N"), new Thread (THREAD01). Start ();//Instantiate the thread class, and start threading new Thread (THREAD02). Start (); new Thread (THREAD03). Start ();}}
Run as follows:

A thread hibernation 1000
B Thread Hibernation 2000
C Thread Hibernation 3000

Java thread Start (implement Runnable interface)

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.