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 }

  • 相关阅读:
    触摸事件传递与响应者链条
    运动事件Motion Events
    手势识别
    MVC模式
    单例模式
    观察者模式(一对多)
    关于多线程的介绍
    Sandbox简介和路径获取
    NSFileManager和NSFileHandle使用
    归档储存
  • 原文地址:https://www.cnblogs.com/zyzblogs/p/11268232.html
Copyright © 2011-2022 走看看