线程

public class Thread1 {

	public static void main(String[] args) {
			//TestThread t = new TestThread();
			TestThread2 tt = new TestThread2();
			//Thread t2 = new Thread(t);
			tt.start();//子类继承了父类的方法,可以直接调用
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
				
			}
			/*t2.start();
			for (int i = 0; i < 10; i++) {
				System.out.println("-----"+ i);
			}		*/
	}
		//没有先后顺序,随机出来
	
}

  class TestThread2 extends Thread{  //继承

	@Override
	public void run() {
		/*for (int i = 0; i < 10; i++) {
			System.out.println("***"+ i);
		}*/
		boolean flag = true;
		public static void shuuatdown() {
			
		}
		while (flag) {
			System.out.println(new Date());
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				//e.printStackTrace();
				return;
			}
		}
		
	}
	 
	  
  }


class TestThread implements Runnable{  //给一个接口,这种方法更好一些,因为可以解决单继承的问题
	@Override
	public void run() {  //重写
		for (int i = 0; i < 10; i++) {
			System.out.println("====="+ i);
		}
	}
	
}
原文地址:https://www.cnblogs.com/zuo72/p/8018166.html