java 每隔一秒_java线程:每隔一秒输出一个数据

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 00:04   27   0

public static void main(String[] args) {

BlockingQueue queue = new LinkedBlockingQueue();

ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 6, 1, TimeUnit.DAYS, queue);

for (int i = 0; i < 20; i++) {

executor.execute(new Runnable() {

public void run() {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println(String.format("thread %d finished", this.hashCode()));

}

});

}

executor.shutdown();

}

取消

评论

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP