zoukankan      html  css  js  c++  java
  • java例程练习(多线程[sleep()方法])

    import java.util.*;
    public class Test {
    	public static void main(String[] args) {
    		MyThread thread = new MyThread();
    		thread.start();
    		try {
    			Thread.sleep(10000);//主线程睡眠
    			
    		} catch(InterruptedException e) { }
    		
    		thread.interrupt();          //-----------不是最好的方法
    		//thread.flag = false;       //-----------此方法是终止线程的推荐方法							
    		
    	}
    }
    
    class MyThread extends Thread {
    	boolean flag = true;
    	public void run() {
    		//每隔一秒钟打印一次时间
    		while(flag) {
    			System.out.println
    				("====" + new Date() + "====");
    			
    			try{
    				sleep(1000);
    			} catch(InterruptedException e) { //----此异常必须处理
    				return;
    			}
    		}
    	}
    }

  • 相关阅读:
    bys_tu_2016
    ciscn_2019_es_1
    jarvisoj_level5
    axb_2019_brop64
    [ZJCTF 2019]EasyHeap
    ciscn_2019_es_7
    Exp1 PC平台逆向破解 相关wp
    picoctf_2018_shellcode
    cmcc_simplerop
    axb_2019_fmt32
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671695.html
Copyright © 2011-2022 走看看