package com.JUnit;
/**
* java线程测试
* @author RSun
* @Date 2012-10-26下午02:12:56
* @Email
*/
public class Test {
public static void main(String[] args) {
new TestThread().start();
new TestThread("呵呵").start();
new Thread(new TestRunnable()).start();
new Thread(new TestRunnable("哈哈")).start();
// 下面的调用方法达不到新线程效果,永远都会先执行AAAAAA,然后才执行BBBBBB
// new TestRunnable("AAAAAA").run();
// new TestRunnable("BBBBBB").run();
System.out.println("输出顺序是否每次都不一样呢?");
}
}
/** extends方式实现线程 **/
class TestThread extends Thread{
private String s;
public TestThread(){
}
public TestThread(String ss){
this.s = ss;
}
@Override
public void run() {
System.err.println("Thread线程启动:" + s);
}
}
/** implements方式实现线程 **/
class TestRunnable implements Runnable{
private String s;
public TestRunnable(){
}
public TestRunnable(String ss){
this.s = ss;
}
Override
ublic void run() {
System.err.println("Runnable线程启动:" + s);
}
}