Simple thread runnable to implement thread testing

Source: Internet
Author: User

/*
Demand:
Write a simple threading test that takes the implementation of the runnable run ()
Print a sentence simple custom thread name statement thread World Wecome you!!
and the default thread name statement: This is defalut threadname: Default thread Name
*/

Class Test_thread implements runnable{
private String name;
public void GetName (String name) {
This.name=name;
}
public void Show (Object obj) {
System.out.println (obj);
}
public void Run () {
if (name== "Xiao Ming")
Show (name+ ": Runnable World Wecome you!! ");
Else
Show ("This is Defalut threadname:" +thread.currentthread (). GetName ());
}

}

public class runnabletest{

public static void Main (String args[]) {
To create a thread object
Test_thread tt=new Test_thread ();
Test_thread tt2=new Test_thread ();
Encapsulating a thread object into thread
Thread t1=new thread (TT);
Thread t2=new thread (TT2);
Tt2.getname ("Xiao Ming");
Start Start ();
T1.start ();
T2.start ();
}
}
/*
Printing results:
This is Defalut threadname:thread-0
Xiaoming: Thread World Wecome you!!
*/

Simple thread runnable to implement thread testing

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.