package com.fintech.marketing.util;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolTest {
public static void main(String[] args) throws InterruptedException {
ExecutorService pool = Executors.newFixedThreadPool(100);
ArrayList<Callable<Integer>> callers = new ArrayList<Callable<Integer>>();
long start = System.currentTimeMillis();
int len = 1000;
for (int i = 0; i < len; i++) {
callers.add(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
String threadName = Thread.currentThread().getName();
System.out.println("threadName:" + threadName);
Thread.sleep(1000);
return 0;
}
});
}
pool.invokeAll(callers);
long end = System.currentTimeMillis();
System.out.println("共耗时:" + (end - start) +"ms");
System.out.println("done!");
pool.shutdown();
}
}
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadPoolTest {
public static void main(String[] args) throws InterruptedException {
ExecutorService pool = Executors.newFixedThreadPool(100);
ArrayList<Callable<Integer>> callers = new ArrayList<Callable<Integer>>();
long start = System.currentTimeMillis();
int len = 1000;
for (int i = 0; i < len; i++) {
callers.add(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
String threadName = Thread.currentThread().getName();
System.out.println("threadName:" + threadName);
Thread.sleep(1000);
return 0;
}
});
}
pool.invokeAll(callers);
long end = System.currentTimeMillis();
System.out.println("共耗时:" + (end - start) +"ms");
System.out.println("done!");
pool.shutdown();
}
}