日期:2014-05-20 浏览次数:21012 次
public class Testing
{
    private static TestThread tester;
    class TestThread extends Thread
    {
        private int index = 0;
        private boolean running = true;
        @Override
        public void run()
        {
            while (running)
            {
                System.out.println("" + ++index);
                try
                {
                    Thread.sleep(500);
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }
        }
        public void setRunning(boolean running)
        {
            this.running = running;
        }
    }
    public static void main(String[] args)
    {
        // 开启线程
        tester = new TestThread();
        tester.start();
        // 消毁线程
        tester.setRunning(false);
        tester = null;