ExecutorService - Java - Parallel execution
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
ExecutorService executor = Executors.newFixedThreadPool(2);
Runnable worker1 = new accumulator();
executor.execute(worker1);
Runnable worker2 = new claim();
executor.execute(worker2);
executor.shutdown();
// Wait until all threads are finish
while (!executor.isTerminated()) {
}
public class accumulator implements Runnable {
@Override
public void run() {
try {
} catch(Exception e){
e.printStackTrace();
}
}
}
public class claim implements Runnable {
@Override
public void run() {
try {
} catch(Exception e){
e.printStackTrace();
}
}
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
ExecutorService executor = Executors.newFixedThreadPool(2);
Runnable worker1 = new accumulator();
executor.execute(worker1);
Runnable worker2 = new claim();
executor.execute(worker2);
executor.shutdown();
// Wait until all threads are finish
while (!executor.isTerminated()) {
}
public class accumulator implements Runnable {
@Override
public void run() {
try {
} catch(Exception e){
e.printStackTrace();
}
}
}
public class claim implements Runnable {
@Override
public void run() {
try {
} catch(Exception e){
e.printStackTrace();
}
}
}