22 lines
475 B
Java
22 lines
475 B
Java
abstract class Concurrent<ArgType> {
|
|
private ArgType[] args;
|
|
|
|
public Concurrent(ArgType[] args) {
|
|
this.args = args;
|
|
}
|
|
|
|
void run() throws InterruptedException {
|
|
Thread[] threads = new Thread[args.length];
|
|
|
|
for (int i = 0; i < args.length; i++) {
|
|
final ArgType arg = args[i];
|
|
threads[i] = new Thread(() -> perform(arg));
|
|
threads[i].start();
|
|
}
|
|
for (int i = 0; i < threads.length; i++) {
|
|
threads[i].join();
|
|
}
|
|
}
|
|
|
|
abstract void perform(ArgType arg);
|
|
} |