Java Api 之Thread Join

/ JAVA API / 没有评论 / 397浏览

线程的协调

线程的同步和异步


public class JoinDemo {
    //标识图片是否下载完毕
    public static boolean isFinish = false;
    public static void main(String[] args) {
        Thread download = new Thread() {
	     public void run() {
	         System.out.println("down:开始下载图片。。。");
		      for (int i = 0; i <= 100; i += 10) {
		          System.out.println("down:已下载 " + i + "%");
			      try {
				      Thread.sleep(50);
				  } catch (InterruptedException e) {
				  }
				}
		  System.out.println("down:图片下载完成!");
		  isFinish = true;
			}
		};
		download.start();
    }
}