Parallel execution in Java

public void doParallel(Runnable... runnables) {
    List<Thread> threads = new ArrayList<>();
    Arrays.asList(runnables).forEach(runnable -> threads.add(new Thread(runnable)));
    threads.forEach(thread -> thread.start());
    threads.forEach(thread -> { try { thread.join(); } catch (InterruptedException e) {}});
}
doParallel(
    () -> doSomething(),
    () -> doSomething(),
    () -> doSomething()
);

Recommended Posts

Parallel execution in Java
Measured parallel processing in Java
External process execution in Java
Partization in Java
Changes in Java 11
Pi in Java
FizzBuzz in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
Callable Interface in Java
Parallel and parallel processing in various languages (Java edition)
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Initializing HashMap in Java
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Get EXIF information in Java
Save Java PDF in Excel
[Neta] Sleep Sort in Java
Edit ini in Java: ini4j
Java history in this world
Let Java segfault in 6 lines
Java debug execution [for Java beginners]
Try calling JavaScript in Java
Try developing Spresense in Java (1)
Try functional type in Java! ①
I made roulette in Java.
Implement two-step verification in Java
Refactoring: Make Blackjack in Java
Write flyway callbacks in Java
Topic Analysis (LDA) in Java
Importing Excel data in Java 2
NEologd preprocessing in Java neologdn-java
Change java encoding in windows
Java Stream API in 5 minutes