Search This Blog

Total Pageviews

Multi Thread Example using Execution Service

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import static java.util.Arrays.asList ;

public class ExecutorServiceMultiThreadSubstraction
    static class Substract implements Callable<Long> {
        private long b;
        private long a;
        Substract(long a, long b){
            this.a = a ;
            this.b = b ;
        public Long call() throws Exception
            return a-b;
        public static void main(String str[]) throws Exception{
            ExecutorService executor = Executors.newFixedThreadPool(5) ;
            List<Future<Long>> results = executor.invokeAll(asList(new Substract(0,10), new Substract(11,13), new Substract(14,15) )) ;            
            executor.shutdown() ;            
            for(Future<Long> result: results)
                System.out.println(result.get()) ;

No comments:

Windows 8.3 file naming setting is disabled for the product

To enable Windows 8.3 file naming setting use fsutil command Example:  c:\> fsutil 8dot3name set C: 0