java线程实现有两种方式:继承Thread、实现Runnable。
package com.ch.thread;
public class ThreadTest extends Thread {
public ThreadTest(String name) {
super(name);
// TODO Auto-generated constructor stub
}
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
for(int i = 0 ;i< 100;i++) {
System.out.println(this.getName()+"线程运行ing、、、");
}
}
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
ThreadTest tt = new ThreadTest("thread one");
ThreadTest tt2 = new ThreadTest("thread two");
tt.start();
//tt.join();
tt2.start();
}
}
package com.ch.thread;
public class ThreadImpl implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("线程运行、、、");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ThreadImpl ti = new ThreadImpl();
Thread tt = new Thread(ti);
tt.start();
}
}