Package com. JUnit;
/**
* Java Threading Test
* @author RSun
* @Date 2012-10-26 02:12:56
* @Email
*/
public class Test {
public static void Main (string[] args) {
New Testthread (). Start ();
New Testthread ("hehe"). Start ();
New Thread (New Testrunnable ()). Start ();
New Thread (New testrunnable ("haha")). Start ();
The following invocation method does not reach the new thread effect and will always execute the aaaaaa before executing the BBBBBB
New Testrunnable ("Aaaaaa"). Run ();
New Testrunnable ("BBBBBB"). Run ();
SYSTEM.OUT.PRINTLN ("Output order is different every time.") ");
}
}
/** extends way to implement thread **/
Class Testthread extends thread{
Private String S;
Public Testthread () {
}
Public Testthread (String ss) {
THIS.S = SS;
}
@Override
public void Run () {
SYSTEM.ERR.PRINTLN ("Thread Threads start:" + s);
}
}
/** implements mode implementation thread **/
class Testrunnable implements runnable{
private String S;
public testrunnable () {
}
public testrunnable (String ss) {
THIS.S = SS;
}
Override
ublic void Run () {
System.err.println ("runnable thread Start:" + s);
}
}