Saturday 7 December 2019

Thread Pool-Executor Service


 Implementing Executor Service in Java

   When you want to get the data from the various services and make the service calls concurrently.


    ExecutorService executors = Executors.newFixedThreadPool(2);  //creats the thread pool of size 2

        //Using method reference
   Callable<Map<Integer, String>> service1cal= service1::getData; 

       //Using lamda expression
Callable<List<SomeBean>> service2cal= ()-> {
          service2.getData(input1);
       };


       Future<Map<Integer, String>> service1f= executors.submit(service1cal);
       Future<List<SomeBean>> service2f= executors.submit(service2cal);
 
       Map<Integer, String>  service1datamap=service1f.get();  //its a blocking statement ,it will make the main thread to wait until its ex
       List<SomeBean> service2list=service2f.get();
       executors.shutdown();
Location:Bangalore Sri Laxmi Adinarayan Arcade, 1st Phase, JP Nagar, Bengaluru, Karnataka 560041, India

6 comments:

  1. Sun pool domes provide another great way to use the sun's energy as a heating source for your swimming pool. Typically constructed from vinyl and aluminum, sun pool domes provide a complete enclosure for your swimming pool, preventing heat loss and also helping to keep your pool clean. Pool selber bauen

    ReplyDelete
  2. Fascinating information I haven’t been website design studios experienced such information in quite a long time.

    ReplyDelete
  3. Woh I love your blog posts, saved to my bookmarks ! . visit the site

    ReplyDelete
  4. Dazzling visual displays can be seen as the LED and fiber optic lights shift in color and set the mood for a romantic late-night swim or a bustling backyard bash. Swimmingpool

    ReplyDelete
  5. Your website is terribly informative and your articles are wonderful.
    app development studio

    ReplyDelete