threadpool

ThreadPool of CLI Processes

时间秒杀一切 提交于 2019-12-06 03:53:51
问题 I need to pass messages to CLI PHP processes via stdin from Java. I'd like to keep about 20 PHP processes running in a pool, such that when I pass a message to the pool, it sends each message to a separate thread, keeping a queue of messages to be delivered. I'd like these PHP processes to stay alive as long as possible, bringing up a new one if one dies. I looked at doing this with a static thread pool, but it seems more designed for tasks that execute and simply die. How could I do this,

Does awaitTermination in ExecutorService “happens-before” any code executed after it?

一曲冷凌霜 提交于 2019-12-06 03:32:07
问题 Please, help to understand ExecutorService#awaitTermination(timeout) behaviour. I'm observing situation when I have in my code: private void shutdownAndAwaitTermination(ExecutorService threadPool){ threadPool.shutdown(); try { if (!threadPool.awaitTermination(threadPoolTimeout, TimeUnit.HOURS)){ threadPool.shutdownNow(); if (!threadPool.awaitTermination(60, TimeUnit.SECONDS)) { logger.warn("Pool did not terminate"); } } } catch (InterruptedException ie) { threadPool.shutdownNow(); Thread

newFixedThreadPool() vs newCachedThreadPool() [duplicate]

依然范特西╮ 提交于 2019-12-06 03:16:26
This question already has an answer here: Executors.newCachedThreadPool() versus Executors.newFixedThreadPool() 8 answers In case newCachedThreadPool() as per creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available whereas in case of newFixedThreadPool(int size) specify size to create the thread pool with size specified. Why isn't newFixedThreadPool(int size) implemented in newCachedThreadPool() fashion where thread pool creates the new thread only when required and will limit the thread to size? Any clarrification on the

Does Java provide an ExecutorService which allows a worker to execute on the same thread?

感情迁移 提交于 2019-12-06 03:16:18
问题 I am looking for an implementation of ExecutorService which will provide the following semantics. Each thread is occupied by a 'worker' that performs some task based on an input. Each worker is guaranteed to only execute in a single thread, thus, it should be allowed to maintain state from task to task, without the overhead of synchronisation, since it would be synchronising with itself, in a single thread. So let's say I have 100 inputs, and 10 workers, I would like to be able to write

Does WCF Service use multiple threads to process incoming requests?

馋奶兔 提交于 2019-12-06 03:13:07
问题 How can I ensure that a WCF service uses threads from a ThreadPool to process incoming messages? At the moment simple method invocation like 'return null;' takes about 45 seconds while another requests are processing Here is how I have annotated my service class: [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)] public partial class MyService : IMyService { ... } But when I'm watching the process in task manager it seems to be

ThreadPoolExecutor's getActiveCount()

不想你离开。 提交于 2019-12-06 02:53:39
问题 I have a ThreadPoolExecutor that seems to be lying to me when I call getActiveCount(). I haven't done a lot of multithreaded programming however, so perhaps I'm doing something incorrectly. Here's my TPE @Override public void afterPropertiesSet() throws Exception { BlockingQueue<Runnable> workQueue; int maxQueueLength = threadPoolConfiguration.getMaximumQueueLength(); if (maxQueueLength == 0) { workQueue = new LinkedBlockingQueue<Runnable>(); } else { workQueue = new LinkedBlockingQueue

boost thread pool

折月煮酒 提交于 2019-12-06 02:51:52
I need a threadpool for my application, and I'd like to rely on standard (C++11 or boost) stuff as much as possible. I realize there is an unofficial(!) boost thread pool class, which basically solves what I need, however I'd rather avoid it because it is not in the boost library itself -- why is it still not in the core library after so many years? In some posts on this page and elsewhere, people suggested using boost::asio to achieve a threadpool like behavior. At first sight, that looked like what I wanted to do, however I found out that all implementations I have seen have no means to join

How to detect scala executioncontext exhaustion?

余生颓废 提交于 2019-12-06 02:49:51
问题 I'm having problems with my Playframework application not being responsive from time to time and I would like to detect this at runtime + log information on what is currently running on the exhausted execution context. What would the best strategy for implementing this be? I thought about posting small runnables to the execution contexts and if they don't get executed in time I would log a warning. This max wait time should of course be configurable. Eg the main web execution context should

Generic ThreadPool in .NET

本小妞迷上赌 提交于 2019-12-06 02:26:47
问题 Here's a relatively common task for me, and, I think, for many a .NET programmer: I want to use the .NET ThreadPool for scheduling worker threads that need to process a given type of tasks. As a refresher, the signatures for the queueing method of the ThreadPool and its associated delegate are: public static bool QueueUserWorkItem ( WaitCallback callBack, Object state ) public delegate void WaitCallback (Object state) Therefore, a typical generic worker thread class would look something like:

Limiting the number of threadpool threads

ε祈祈猫儿з 提交于 2019-12-05 22:49:17
I am using ThreadPool in my application. I have first set the limit of the thread pool by using the following: ThreadPool.SetMaxThreads(m_iThreadPoolLimit,m_iThreadPoolLimit); m_Events = new ManualResetEvent(false); and then I have queued up the jobs using the following WaitCallback objWcb = new WaitCallback(abc); ThreadPool.QueueUserWorkItem(objWcb, m_objThreadData); Here abc is the name of the function that I am calling. After this I am doing the following so that all my threads come to 1 point and the main thread takes over and continues further m_Events.WaitOne(); My thread limit is 3. The