/**
* <p>title: Implements the Runnable interface to obtain a thread. </p>
* <p>description: Obtains its own thread (T2) by implementing the Runnable interface. </p>
* <p>copyright:copyright (c) 2003</p>
* <p>Filename:twothread.java</p>
* @version 1.0
*/
public class Twothread implements Runnable {
/**
*<br> method Description: Builder. The actual thread, and start this thread.
*<br> Input parameters:
*<br> return type:
*/
Twothread () {
//get current thread
Thread T1 =thread.currentthread ( );
T1.setname ("The" the "the" the "");
System.out.println ("The Running thread:" + T1);
//Constructs a thread by using this class (Runnable interface) and name
thread t2 = new Thread (this, "the second Thread");
System.out.println ("creat another Thread");
//Start thread
T2.start ();
try {
System.out.println ("I Thread'll Sleep");
Thread.Sleep (3000);
}catch (interruptedexception e) {
System.out.println ("The" the "A-thread has wrong");
System.out.println ("A-thread exit");
}
/**
*<br> Method Description: Thread body. Implement the Run method.
*<br> Input parameters:
*<br> return type:
*/
public void Run () {
try {
for (int i=0;i<5;i++) {
System.out.println ("Sleep Time for Thread 2:" +i);
Thread.Sleep (1000);
}
catch (Interruptedexception e) {
System.out.println ("thread has wrong");
System.out.println ("Second thread Exit");
}
/**
*<br> Method Description: Main method
*<br> input parameter:
*<br> return type:
*/
public static void main ( String args[]) {
New Twothread ();
}
}