标签:imp sdn http cpu ide 资源 extends pre mod
这样。就提高了程序的运行效率。
public class MyThread1 extends Thread {
public MyThread1(String name) {
super(name);
}
public void run() {
System.out.println(this.getName());
}
public static void main(String[] args) {
Thread t1 = new MyThread1("阿三");
t1.start();
}
}
public class MyThread implements Runnable {
private String name;
public MyThread(String name) {
this.name = name;
}
@Override
public void run() {
System.out.println(name);
}
public static void main(String[] args) {
Thread tt1 = new Thread(new MyThread("张三"));
tt1.start();
}
}
/**
* 启动子线程的方式(使用内部类定义另外一个线程)
* @author XuJijun
*
*/
public class MyThread {
public static void main(String[] args) {
(new MyThread()).new AnotherThread("张三").start();
}
/**
* 内部类,实现子线程
*
*/
private class AnotherThread extends Thread{
private String msg;
/*
* 加一个參数,用于接收主线程的信息
*/
public AnotherThread(String msg) {
super();
this.msg = msg;
}
@Override
public void run() {
System.out.println("Hello " + msg);
}
}
}a.join();
System.out.print("End"); //等待线程a结束后再打印出“End”标签:imp sdn http cpu ide 资源 extends pre mod
原文地址:http://www.cnblogs.com/clnchanpin/p/7026849.html