Skip to content

Instantly share code, notes, and snippets.

@PatrickGopher
Created July 17, 2020 05:48
Show Gist options
  • Save PatrickGopher/92f0a2564632f27ff0c983b5e7b33b41 to your computer and use it in GitHub Desktop.
Save PatrickGopher/92f0a2564632f27ff0c983b5e7b33b41 to your computer and use it in GitHub Desktop.
multithread java
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