{{theTime}}

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 ;
        }
        @Override
        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:

Generate Insert Sql from Select Statement

SELECT 'INSERT INTO ReferenceTable (ID, Name) VALUES (' +        CAST(ID AS NVARCHAR) + ', ''' + Name + ''...