62,629
社区成员
 发帖
 发帖 与我相关
 与我相关 我的任务
 我的任务 分享
 分享
public class ThreadTest extends Thread {
	static volatile String msg = "hello";
	int start;
	
	public ThreadTest(int i,String name){
		this.start = i;
		this.setName(name);
	}
	public static void main(String[] args) {
		ThreadTest test = new ThreadTest(10,"test");
		ThreadTest test1 = new ThreadTest(20,"test1");
		test.start();
		test1.start();
		try {
			test.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("main's msg is "+msg);
		System.out.println("main stoped");
	}
	public void run() {
		String threadName = Thread.currentThread().getName();
		System.out.println(threadName+" running");
		for (int i = start; i < start+4; i++) {
			msg = msg + " " + i;
		}
		System.out.println(threadName+"'s msg is "+ msg);
		System.out.println(threadName+" stoped");
	}
}