threadpool

AsyncTask.executeOnExecutor() before API Level 11

无人久伴 提交于 2019-11-26 15:56:14
The normal way we do AsyncTask in Android is, from Android API: private class DoIntenseTask extends AsyncTask<Object, Object, Void> { protected Void doInBackground(Object... params) { for (Object param : params) { Object rtnObj = doIntenseJob(param); publishProgress(rtnObj); } return null; } protected void onProgressUpdate(Object... progress) { for (Object rtnObj : progress) { updateActivityUI(rtnObj); } } } My intense tasks are loosely coupled and the execution order does not matter, by doing this way, a single thread is allocated to run a list of intense tasks. personally I think this is a

Using ThreadPool.QueueUserWorkItem in ASP.NET in a high traffic scenario

一笑奈何 提交于 2019-11-26 15:34:56
I've always been under the impression that using the ThreadPool for (let's say non-critical) short-lived background tasks was considered best practice, even in ASP.NET, but then I came across this article that seems to suggest otherwise - the argument being that you should leave the ThreadPool to deal with ASP.NET related requests. So here's how I've been doing small asynchronous tasks so far: ThreadPool.QueueUserWorkItem(s => PostLog(logEvent)) And the article is suggesting instead to create a thread explicitly, similar to: new Thread(() => PostLog(logEvent)){ IsBackground = true }.Start()

C# - ThreadPool vs Tasks

你。 提交于 2019-11-26 15:18:23
问题 As some may have seen in .NET 4.0, they've added a new namespace System.Threading.Tasks which basically is what is means, a task. I've only been using it for a few days, from using ThreadPool. Which one is more efficient and less resource consuming? (Or just better overall?) 回答1: The objective of the Tasks namespace is to provide a pluggable architecture to make multi-tasking applications easier to write and more flexible. The implementation uses a TaskScheduler object to control the handling

c++ work queues with blocking

天涯浪子 提交于 2019-11-26 14:50:02
问题 This question should be a little simpler than my last few. I've implemented the following work queue in my program: Pool.h: // tpool class // It's always closed. :glasses: #ifndef __POOL_H #define __POOL_H class tpool { public: tpool( std::size_t tpool_size ); ~tpool(); template< typename Task > void run_task( Task task ){ boost::unique_lock< boost::mutex > lock( mutex_ ); if( 0 < available_ ) { --available_; io_service_.post( boost::bind( &tpool::wrap_task, this, boost::function< void() > (

Thread pooling in C++11

霸气de小男生 提交于 2019-11-26 13:59:37
Relevant questions : About C++11: C++11: std::thread pooled? Will async(launch::async) in C++11 make thread pools obsolete for avoiding expensive thread creation? About Boost: C++ boost thread reusing threads boost::thread and creating a pool of them! How do I get a pool of threads to send tasks to , without creating and deleting them over and over again? This means persistent threads to resynchronize without joining. I have code that looks like this: namespace { std::vector<std::thread> workers; int total = 4; int arr[4] = {0}; void each_thread_does(int i) { arr[i] += 2; } } int main(int argc

If my interface must return Task what is the best way to have a no-operation implementation?

狂风中的少年 提交于 2019-11-26 12:19:56
问题 In the code below, due to the interface, the class LazyBar must return a task from it\'s method (and for arguments sake can\'t be changed). If LazyBar s implementation is unusual in that it happens to run quickly and synchronously - what is the best way to return a No-Operation task from the method? I have gone with Task.Delay(0) below, however I would like to know if this has any performance side-effects if the function is called a lot (for arguments sake, say hundreds of times a second):

C++ Thread Pool [closed]

人盡茶涼 提交于 2019-11-26 11:57:45
问题 What is a good open source implementation of a thread pool for C++ to use in production code (something like boost)? Please provide either your own example code or a link to example code usage. 回答1: I think it is still not accepted into Boost, but a good staring point: threadpool. Some example of usage, from the web site: #include "threadpool.hpp" using namespace boost::threadpool; // Some example tasks void first_task() { ... } void second_task() { ... } void third_task() { ... } void

Should i use ThreadPools or Task Parallel Library for IO-bound operations

。_饼干妹妹 提交于 2019-11-26 11:48:50
问题 In one of my projects that\'s kinda an aggregator, I parse feeds, podcasts and so from the web. If I use sequential approach, given that a large number of resources, it takes quite a time to process all of them (because of network issues and similar stuff); foreach(feed in feeds) { read_from_web(feed) parse(feed) } So I want to implement concurrency and couldn\'t decide if I should basically use ThreadPools to process with worker threads or just rely on TPL to get it sorted. ThreadPools for

Java: ExecutorService that blocks on submission after a certain queue size

陌路散爱 提交于 2019-11-26 11:48:42
问题 I am trying to code a solution in which a single thread produces I/O-intensive tasks that can be performed in parallel. Each task have significant in-memory data. So I want to be able limit the number of tasks that are pending at a moment. If I create ThreadPoolExecutor like this: ThreadPoolExecutor executor = new ThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(maxQueue)); Then the executor.submit(callable) throws

What is the async/await equivalent of a ThreadPool server?

房东的猫 提交于 2019-11-26 11:48:28
I am working on a tcp server that looks something like this using synchronous apis and the thread pool: TcpListener listener; void Serve(){ while(true){ var client = listener.AcceptTcpClient(); ThreadPool.QueueUserWorkItem(this.HandleConnection, client); //Or alternatively new Thread(HandleConnection).Start(client) } } Assuming my goal is to handle as many concurrent connections as possible with the lowest resource usage, this seems that it will be quickly limited by the number of available threads. I suspect that by using Non-blocking Task apis, I will be able to handle much more with fewer