threadpool

Thread.Start() versus ThreadPool.QueueUserWorkItem()

跟風遠走 提交于 2019-11-28 16:12:15
The Microsoft .NET Base Class Library provides several ways to create a thread and start it. Basically the invocation is very similar to every other one providing the same kind of service: create an object representing an execution flow (or more), assign it a delegate representing the execution flow to execute and, eventually, depending on delegate signature, an object as a parameter. Well, there are two approaches (essentially): 1) Using the System.Threading.Thread class. Thread curr = new Thread(myfunction); /* In a class, myfunction is a void taking an object */ curr.Start(new Object()); /*

What's the advantage of a Java-5 ThreadPoolExecutor over a Java-7 ForkJoinPool?

為{幸葍}努か 提交于 2019-11-28 15:58:54
问题 Java 5 has introduced support for asynchronous task execution by a thread pool in the form of the Executor framework, whose heart is the thread pool implemented by java.util.concurrent.ThreadPoolExecutor. Java 7 has added an alternative thread pool in the form of java.util.concurrent.ForkJoinPool. Looking at their respective API, ForkJoinPool provides a superset of ThreadPoolExecutor's functionality in standard scenarios (though strictly speaking ThreadPoolExecutor offers more opportunities

C# - When to use standard threads, ThreadPool, and TPL in a high-activity server

五迷三道 提交于 2019-11-28 15:39:51
问题 I've been reading a lot about threading lately as I am looking to develop a high-performance, scalable TCP server capable of handling up to 10,000-20,000 clients, each client of which is consistently communicating bidirectionally to the server with a command-based system. The server will receive a command, and execute either a single (or many) tasks as per the command. My question is how to appropriately make use of the .NET threading constructs for a variety of situations, executing tasks

Ensuring task execution order in threadpool

隐身守侯 提交于 2019-11-28 15:25:35
I have been reading about the thread-pool pattern and I can't seem to find the usual solution for the following problem. I sometimes want tasks to be executed serially. For example, I read chunks of text from a file and for some reason I need the chunks to be processed in that order. So basically I want to eliminate concurrency for some of the tasks . Consider this scenario where the tasks with * need to be processed in the order they were pushed in. The other tasks can be processed in any order. push task1 push task2 push task3 * push task4 * push task5 push task6 * .... and so on In the

Multithreaded job queue manager

回眸只為那壹抹淺笑 提交于 2019-11-28 14:32:45
问题 I need to manage CPU-heavy multitaskable jobs in an interactive application. Just as background, my specific application is an engineering design interface. As a user tweaks different parameters and options to a model, multiple simulations are run in the background and results displayed as they complete, likely even as the user is still editing values. Since the multiple simulations take variable time (some are milliseconds, some take 5 seconds, some take 10 minutes), it's basically a matter

How to get thread id from a thread pool?

放肆的年华 提交于 2019-11-28 14:22:44
问题 I have a fixed thread pool that I submit tasks to (limited to 5 threads). How can I find out which one of those 5 threads executes my task (something like "thread #3 of 5 is doing this task")? ExecutorService taskExecutor = Executors.newFixedThreadPool(5); //in infinite loop: taskExecutor.execute(new MyTask()); .... private class MyTask implements Runnable { public void run() { logger.debug("Thread # XXX is doing this task");//how to get thread id? } } 回答1: Using Thread.currentThread() :

Cross-thread operation not valid in Windows Forms

旧街凉风 提交于 2019-11-28 13:48:28
Could anyone help me i have a problem I'm trying to get this code to work in the background via threadpool but i cannot seem to get it to work i keep getting this error: Cross-thread operation not valid: Control 'ListBox3' accessed from a thread other than the thread it was created on. Here is the code i am using: private void DoWork(object o) { var list = ListBox3; var request = createRequest(TxtServer.Text, WebRequestMethods.Ftp.ListDirectory); using (var response = (FtpWebResponse)request.GetResponse()) { using (var stream = response.GetResponseStream()) { using (var reader = new

Android - Async Task behavior in 2.3.3 and 4.0 OS

不羁岁月 提交于 2019-11-28 11:31:32
I am testing an application where we have a list view with list of images retrieved over network. When i run the application on android device 2.3.3 (WIFI speed 512 KBPS) and check the DDMS (Thread Viewer), the number of threads keeps increasing till 50 from 25. But when i test the same application on device 4.0 (WIFI speed 5 MBPS), number of threads did not increase. Can anyone help me understand why this is happening ? Is it due to android OS difference or any other reason ? Thanks in advance. Ponyets Are you useing AsyncTask . After Android 3.0, the default behavior of AsyncTask is execute

Will values in my ThreadStatic variables still be there when cycled via ThreadPool?

本秂侑毒 提交于 2019-11-28 10:56:56
I am using ThreadStatic variables to store some data, but I am worried that the data I store on the thread will still be there after I am finished with it and release back to the ThreadPool. Do I need to worry about clearing my ThreadStatic variables before I am finished with the thread? Or will the ThreadPool do this for me before "passing it out" for the next QueueUserWorkItem? This is especially important for me because I need to make sure that other threads in my app have a clean slate to work from in terms of ThreadStatic variables. Thanks! The thread pool (by design) keeps the threads

System.OutOfMemoryException' was thrown - WebClient.DownloadStringAsynch()

╄→尐↘猪︶ㄣ 提交于 2019-11-28 10:51:32
问题 I'm writing a poor mans load tester and I thought I was managing my resources correctly (thread pool) but when I run the following code I get an OutOfMemoryException on my call to WebClient.DownloadStringAsynch. Using .net4.0 but could move to 4.5. ASKs: What is the fix? How could I use HttpWebRequest and send that asynch as an alternative to webclient? What about using .net 4.5 using await (any difference with how .net4 manages threads with asynch calls? static void Main(string[] args) {