Created
July 17, 2020 05:48
-
-
Save PatrickGopher/92f0a2564632f27ff0c983b5e7b33b41 to your computer and use it in GitHub Desktop.
multithread java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ExecutorService executor = Executors.newFixedThreadPool(5); | |
List<Future<String>> list = new ArrayList<>(); | |
for(int i=0; i< 100; i++){ | |
Future<String> future = executor.submit(() -> "222"); | |
list.add(future); | |
} | |
for(Future<String> fut : list){ | |
try { | |
System.out.println(new Date()+ "::"+fut.get()); | |
} catch (InterruptedException | ExecutionException e) { | |
e.printStackTrace(); | |
} | |
} | |
executor.shutdown(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment