【www.gdgbn.com--js教程】

实现多线程的两种方法.
/**继承Thread类*/
public class Test extends Thread {
 public Test() {
  Thread t = new Thread(this);
  t.start();
 }
 public static void main(String[] args) {
  Test t = new Test();
 }
 public void run(){
  while(true)
   System.out.println("继承Thread类");
 }
}
/**实现Runnable接口*/
public class Test2 implements Runnable {
 public Test2(){
  Thread t = new Thread(this);
  t.start();
 }
 public static void main(String[] args) {
  Test2 t2 = new Test2();
 }
 public void run() {
  while(true)
   System.out.println("实现Runnable接口");
 }
 



本文来源:http://www.gdgbn.com/wangyezhizuo/13552/