首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java多线程(容易程序)

2012-10-15 
java多线程(简单程序)import java.util.concurrent.*public class Main implements Runnable {public voi

java多线程(简单程序)

import java.util.concurrent.*;   public class Main implements Runnable {     public void run() {          try {              while (true) {                  TimeUnit.MILLISECONDS.sleep(150);                  System.out.println(Thread.currentThread() + " " + this);              }          } catch (InterruptedException e) {              System.out.println("sleep() interrupted");          }      }        public static void main(String[] args) throws Exception {          for (int i = 0; i < 10; i++) {              Thread daemon = new Thread(new Main());              daemon.setDaemon(true); // Must call before start()              daemon.start();          }          System.out.println("All daemons started");          TimeUnit.MILLISECONDS.sleep(175);      }  } 
?

热点排行