其他分享
首页 > 其他分享> > 线程池

线程池

作者:互联网

package com.cj.java1;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class NumThread2 implements Runnable{
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i%2==0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}
class NumThread3 implements Runnable{
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i%2!=0){
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}
public class ThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        executorService.execute(new NumThread2());//适用于Runnable
        executorService.execute(new NumThread3());//适用于Runnable
        //executorService.submit() //适用于callable
    }
}

 

标签:Runnable,java,void,线程,import,executorService,public
来源: https://www.cnblogs.com/cciscc/p/16094544.html