I tried to read to file in same time and return the number of line
ExecutorService executor = Executors.newFixedThreadPool(2);
FutureTask<Integer> futureOne = new FutureTask<Integer>(new Calcul1());
FutureTask<Integer> futureTwo = new FutureTask<Integer>(new Calcul2());
executor.execute(futureOne);
executor.execute(futureTwo);
while (!(futureOne.isDone() && futureTwo.isDone())) {
}
System.out.println(futureOne.get() + futureTwo.get());
executor.shutdown();
That work well but i found is faster if i read file 1 and after file 2... so i don't get any performance boost with futureTash
Why?
I suspect that your application is completely IO bound. When you are reading a single file in one thread you would see better performance because you are accessing your files sequentially. When you start two threads, you are reading from two different files which is in effect causing the disk to seek back and forth between the two files. If we are talking about spinning platter type disks, the seek time is a significant portion of the IO.