zoukankan      html  css  js  c++  java
  • 线程调度

     1 package com.example.demo.thread.threadpool;
     2 
     3 import java.util.Random;
     4 import java.util.concurrent.*;
     5 
     6 /**
     7  * 文件名:ScheduledThreadPool
     8  * 作 者:Miles zhu
     9  * 时 间:2019/7/30 9:49
    10  * -------------------------
    11  * 功能和描述:
    12  **/
    13 public class TestScheduledThreadPool {
    14     public static void main(String[] args) throws ExecutionException, InterruptedException {
    15         ScheduledExecutorService pool = Executors.newScheduledThreadPool(5);
    16         for (int i = 0; i < 5; i++) {
    17             Future<Integer> future = pool.schedule(new Callable<Integer>() {
    18                 @Override
    19                 public Integer call() throws Exception {
    20                     int num = new Random().nextInt(100);
    21                     System.out.println(Thread.currentThread().getName() + "-" + num);
    22                     return num;
    23                 }
    24             }, 3, TimeUnit.SECONDS);
    25             System.out.println(future.get());
    26         }
    27         pool.shutdown();
    28     }
    29 }

  • 相关阅读:
    Node.js 常用工具 util
    jQuery 选择器
    Node.js 创建HTTP服务器
    Node.js GET/POST请求
    JavaScript 用法
    Node.js 事件
    Node.js 函数
    Bootstrap<基础二> 网格系统
    读文章《Flexbox详解》笔记
    好文要读
  • 原文地址:https://www.cnblogs.com/zyzblogs/p/11268232.html
Copyright © 2011-2022 走看看