threadpool

What is the difference between “seda + concurrentConsumers” and “direct + threads”

穿精又带淫゛_ 提交于 2019-12-04 09:04:18
Apache Camel provide two solutions for using thread pool: from("seda:stageName?concurrentConsumers=5").process(...) and from("direct:stageName").thread(5).process(...) I would like to know, what is the difference between the two solutions ? Is it just two kind of write the same thing or not ? What are the use cases ? SEDA Component The seda: component provides asynchronous SEDA behavior so that messages are exchanged on a BlockingQueue and consumers are invoked in a separate thread to the producer. Direct Component The direct: component provides direct, synchronous invocation of any consumers

C# lower thread priority in thread pool

冷暖自知 提交于 2019-12-04 08:18:10
I have several low-imprtance tasks to be performed when some cpu time is available. I don't want this task to perform if other more import task are running. Ie if a normal/high priority task comes I want the low-importance task to pause until the importance task is done. There is a pretty big number of low importance task to be performed (50 to 1000). So I don't want to create one thread per task. However I believe that the threadpool do not allow some priority specification, does it ? How would you do solve this ? You can new up a Thread and use a Dispatcher to send it takes of various

How do I manage ruby threads so they finish all their work?

白昼怎懂夜的黑 提交于 2019-12-04 08:03:46
问题 I have a computation that can be divided into independent units and the way I'm dealing with it now is by creating a fixed number of threads and then handing off chunks of work to be done in each thread. So in pseudo code here's what it looks like # main thread work_units.take(10).each {|work_unit| spawn_thread_for work_unit} def spawn_thread_for(work) Thread.new do do_some work more_work = work_units.pop spawn_thread_for more_work unless more_work.nil? end end Basically once the initial

Is it really my job to clean up ThreadLocal resources when classes have been exposed to a thread pool?

送分小仙女□ 提交于 2019-12-04 07:56:41
问题 My use of ThreadLocal In my Java classes, I sometimes make use of a ThreadLocal mainly as a means of avoiding unnecessary object creation: @net.jcip.annotations.ThreadSafe public class DateSensitiveThing { private final Date then; public DateSensitiveThing(Date then) { this.then = then; } private static final ThreadLocal<Calendar> threadCal = new ThreadLocal<Calendar>() { @Override protected Calendar initialValue() { return new GregorianCalendar(); } }; public Date doCalc(int n) { Calendar c

Generic ThreadPool in .NET

瘦欲@ 提交于 2019-12-04 07:41:37
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: public class Worker<T> { public void schedule(T i_task) { ThreadPool.QueueUserWorkItem(execute, i_task

Does WCF Service use multiple threads to process incoming requests?

泪湿孤枕 提交于 2019-12-04 07:40:35
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 using a constant number of threads. Even under load. public ActionResult SelectDatabase(string param) { if

ThreadPool of CLI Processes

随声附和 提交于 2019-12-04 07:18:59
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, with a simple interface to pass a message to the pool? Will I have to implement my own custom "thread

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

可紊 提交于 2019-12-04 07:01:51
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.currentThread().interrupt(); } } Does the tasks in pool complete in this case before any other calls after

使用boost实现线程池thread pool | boost thread pool example

女生的网名这么多〃 提交于 2019-12-04 06:46:33
本文首发于个人博客 https://kezunlin.me/post/f241bd30/ ,欢迎阅读! boost thread pool example Guide boost thread pool example with cpp code code example #include <iostream> //std::cout std::endl #include <thread> //std::thread #include <future> //std::future std::promise #include <utility> //std::ref #include <chrono> //std::chrono::seconds #include <boost/thread.hpp> #include <boost/bind.hpp> #include <boost/asio.hpp> class ThreadPool { public: explicit ThreadPool(size_t size) : work_(io_service_) { for (size_t i = 0; i < size; ++i) { workers_.create_thread( boost::bind(&boost::asio::io_service::run, &io

How to detect scala executioncontext exhaustion?

给你一囗甜甜゛ 提交于 2019-12-04 06:24:23
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 never be blocked for more than 1 sec but a background db execution context might allow 30 sec of