package com.git.huanghaifeng.java.thread;

import java.util.ArrayList;
import java.util.List;

public class ThreadDemo extends Thread {

	long minPrime;
	boolean running_flag = true;

	public boolean isRunning_flag() {
		return running_flag;
	}

	public void setRunning_flag(boolean running_flag) {
		this.running_flag = running_flag;
	}

	ThreadDemo(long minPrime) {
		this.minPrime = minPrime;
	}

	@Override
	public void run() {
		while (this.running_flag) {
			System.out.println(this.getName());
			try {
				sleep(6 * 100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(this.getName() + " finish");
	}

	public static void main(String[] args) {
		List<ThreadDemo> list = new ArrayList<ThreadDemo>();
		int thread_num = 3;
        for (int i = 0; i < thread_num; i++) {  
        	ThreadDemo demo = new ThreadDemo(0);  
            demo.start();  
            list.add(demo);  
        }

		try {
			for (ThreadDemo demo : list) {
				Thread.sleep(500);
				demo.setRunning_flag(false);
				//wait for all son thread finish
				demo.join();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		for (ThreadDemo demo : list) {
			System.out.println(demo.getState());
		}
		System.out.println("main thread finish");
	}
}

@@ -332,16 +332,158 @@
 ag;%0A%09%7D%0A%0A
+%09public void stopThread() throws InterruptedException %7B%0A%09%09this.setRunning_flag(false);%0A%09%09//wait for all son thread finish%0A%09%09this.join();%0A%09%7D%0A%09%0A
 %09ThreadD
@@ -533,17 +533,23 @@
 rime;%0A%09%7D
-%0A
+%09%09%09%09%0A%0A%09
 %0A%09@Overr
@@ -1161,81 +1161,17 @@
 mo.s
-etRunning_flag(false);%0A%09%09%09%09//wait for all son thread finish%0A%09%09%09%09demo.join
+topThread
 ();%0A

add queue files