package com.company;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
public class Main2 {
private static final int NTHREADS = 10;
private static final int NTASKS = 100;
public static void main(String[] args) throws ExecutionException, InterruptedException {
double xp = 0, xk=Math.PI, dl = ((Math.PI-0)/NTASKS), dx = 0.00001;
Counter counter = new Counter();
ExecutorService executor = Executors.newFixedThreadPool(NTHREADS);
List<Future<Double>> list = new ArrayList<Future<Double>>();
for(int i=0;i<NTASKS;i++){
double a = xp+i*dl;
double b = xp+(i+1)*dl;
Callable<Double> callable = new Calka_callable(a, b, dx);
Future<Double> future = executor.submit(callable);
list.add(future);
}
double sum = 0;
for(Future<Double> future_double : list){
try{
sum+=future_double.get();
}catch (InterruptedException|ExecutionException e){
e.printStackTrace();
}
}
System.out.println("Suma dla puli watkow : " + sum);
// This will make the executor accept no new threads
// and finish all existing threads in the queue
executor.shutdown();
// Wait until all threads finish
while (!executor.isTerminated()) {
}
System.out.println("Finished all threads");
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}