1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public class Test1 { @Test public void test01() throws Exception {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd"); Callable<LocalDate> task = new Callable<LocalDate>() { @Override public LocalDate call() throws Exception { return LocalDate.parse("20200123",dtf); } }; List<Future<LocalDate>> list = new ArrayList<>(); ExecutorService pool = Executors.newFixedThreadPool(10); for (int i = 1; i <= 10; i++) { Future<LocalDate> future = pool.submit(task); list.add(future); } for (Future<LocalDate> future : list) { System.out.println(future.get()); } pool.shutdown(); } }
|