/*
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