executorservice

How to improve the performance while using ExecutorService with thread timeout capabilities?

烈酒焚心 提交于 2019-12-22 19:01:11
问题 I am not a Multithreading Expert but I am seeing some performance issues with my current code which is using ExecutorService . I am working on a project in which I need to make a HTTP URL call to my server and if it is taking too long time to respond then timeout the call. Currently it is returning simple JSON String back.. Current requirement I have is for 10 ms . Within 10 ms it should be able to get the data back from the server. I guess its possible since it is just an HTTP call to server

How to improve the performance while using ExecutorService with thread timeout capabilities?

拈花ヽ惹草 提交于 2019-12-22 19:01:10
问题 I am not a Multithreading Expert but I am seeing some performance issues with my current code which is using ExecutorService . I am working on a project in which I need to make a HTTP URL call to my server and if it is taking too long time to respond then timeout the call. Currently it is returning simple JSON String back.. Current requirement I have is for 10 ms . Within 10 ms it should be able to get the data back from the server. I guess its possible since it is just an HTTP call to server

How can I implement or find the equivalent of a thread-safe CompletionService?

巧了我就是萌 提交于 2019-12-22 18:16:19
问题 I have a simple web service running inside a Tomcat container, which by nature is multi-threaded. In each request that comes into the service, I want to make concurrent calls to an external service. The ExecutorCompletionService in java.util.concurrent gets me partly there. I can provide it a thread pool, and it will take care of executing my concurrent calls and I will be notified when any of the results are ready. The code to process a particular incoming request might look like: void

Do we need to shutdown ExecutorService fixedThreadPool

混江龙づ霸主 提交于 2019-12-22 08:14:11
问题 I have created threadpool using ExecutorService , in my application to call vendor websrvice, using below code. ExecutorService executor = Executors.newFixedThreadPool(getThreadPoolSize()); for (int i = 0; i < list.size(); i++) { Request ecpReq = list.get(i); thRespLst.add(executor.submit(new Task(ecpReq))); } Wanted to know do we need to take care of shutting down threadpool or something, basically I don't want hanging threads in production environment. 回答1: newFixedThreadPool public static

should ExecutorService be static and global

五迷三道 提交于 2019-12-22 03:52:30
问题 I want to use the same thread pool throughout my application. To this end, I can make ExecutorService static and global so that I can invoke ThreadUtil.executorService to get ExecutorService when I need it. public class ThreadUtil { public static final ExecutorService executorService = Executors.newCachedThreadPool(); } Is it OK to instance multiple thread pools like this? In addition, my application is a TCP server. If I don't know how big the pool should be, is it ok to simply use

How to better use ExecutorService in multithreading environment?

心已入冬 提交于 2019-12-22 03:51:37
问题 I need to make a library in which I will have synchronous and asynchronous methods in it. executeSynchronous() - waits until I have a result, returns the result. executeAsynchronous() - returns a Future immediately which can be processed after other things are done, if needed. Core Logic of my Library The customer will use our library and they will call it by passing DataKey builder object. We will then construct a URL by using that DataKey object and make a HTTP client call to that URL by

Thread Pool Executor Monitoring Requirement

半腔热情 提交于 2019-12-21 23:46:46
问题 In our production environments, we are using Thread Pool Executor to execute runntable task. I need to develop a Thread pool Heartbeat a monitoring system for Thread pool Executor Service: Every 60 seconds, the requirement is to collect following statistic about the Thread Pooled Executor: 1) size of the thread pool 2) length of queue waiting for a thread (a duration or time task waited in blocking queue before thread executed ) 3) Average wait time in queue during the last heartbeat interval

using ScheduledExecutorService to start and stop timer

六月ゝ 毕业季﹏ 提交于 2019-12-21 14:59:28
问题 From my readings, it seems that ScheduledExecutorService is the right way to start and stop timers in Java. I need to port some code that starts and stops a timer. This is not a periodic timer. This code, stops the timer before starting it. So, effectively every start is really a restart(). I am looking for the right way to do this using the ScheduledExecutorService. Here is what I came up with. Looking for comments and insight on things I am missing: ScheduledExecutorService _Timer =

What is the right way to implement sync and async methods in a library?

╄→尐↘猪︶ㄣ 提交于 2019-12-21 13:40:21
问题 I need to make a library in which I will have synchronous and asynchronous feature. executeSynchronous() - waits until I have a result, returns the result. executeAsynchronous() - returns a Future immediately which can be processed after other things are done, if needed. Core Logic of my Library The customer will use our library and they will call it by passing DataKey builder object. We will then construct a URL by using that DataKey object and make a HTTP client call to that URL by

What does 'Thread termination due to failure' refer to?

假装没事ソ 提交于 2019-12-21 04:38:17
问题 The javadoc for ExecutorService sometimes refers to the case when a Thread terminates 'due to failure'. However, it is not clear what kind of failure does this refer to. For instance, the single thread executor documentation says that if this single thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks I would have thought that this situation might happen in case of an Exception, or maybe a RuntimeException ,