threadpool

specifying ThreadPoolExecutor problem

☆樱花仙子☆ 提交于 2019-12-05 10:36:51
Is there any way to create Executor that will have always at least 5 threads, and maximum of 20 threads, and unbounded queue for tasks (meaning no task is rejected) I tried new ThreadPoolExecutor(5, 20, 60L, TimeUnit.SECONDS, queue) with all possibilities that I thought of for queue: new LinkedBlockingQueue() // never runs more than 5 threads new LinkedBlockingQueue(1000000) // runs more than 5 threads, only when there is more than 1000000 tasks waiting new ArrayBlockingQueue(1000000) // runs more than 5 threads, only when there is more than 1000000 tasks waiting new SynchronousQueue() // no

Polling over thousands of TCP sockets

♀尐吖头ヾ 提交于 2019-12-05 10:18:47
I need to connect to thousands of clients over TCP on a proprietary protocol to acquire data cyclically. I need to write a .NET server application in C#. The first attempt was to create for each tcp socket an own thread, which works but needs a lot of cpu usage. I found out that it would be a better idea to use the .NET threadpool instead. As far as I understand ( http://msdn.microsoft.com/en-us/library/ms973903.aspx ) I could use timers in order to get each socket acquire the data cyclically in a given period (like 1 sec). This does not work for me because the sockets time out once the

.NET threading like Node.js/V8?

时间秒杀一切 提交于 2019-12-05 08:58:25
I've been away from .NET desktop programming for some time, while drinking the Node.js koolaid. There are some parts of Node.js I find easy to work with. In particular, I like the simplicity of the threading model, and that I can have a few of the benefits of a multithreaded application while only writing code to keep track of a single thread. Now, I have a need to write a multi-threaded application in .NET, and it occurred to me that there is no reason I cannot use a similar threading model that is used to build Node.js applications . In particular, I want to: Call long-running functions with

Stopping a multi-threaded windows service

和自甴很熟 提交于 2019-12-05 08:11:09
I have a multi-thread windows service in .Net 3.5, and I am having some trouble to stop the service properly when more than one thread is created. This service used to create only one thread to do all the work, and I just changed it to be multi-threaded. It works perfectly, but when the service is stopped, if more than one thread is being executed, it will hang the service until all the threads are completed. When the service is started, I create a background thread to handle the main process: protected override void OnStart(string[] args) { try { //Global variable that is checked by threads

ThreadPool.QueueUserWorkItem in Web Service for “Fire and Forget” task

空扰寡人 提交于 2019-12-05 07:07:10
This is ASP.NET ASMX Web Service / .NET Framework 4.0. In web service, I want to execute one method on another thread something like “Fire and Forget” so that Web Service returns some value in response immediately to web site. That method on another thread could take 10 minutes after Web Service returns response immediately to Web site. Also, I do not need return value of that method. I have tested this scenario using ThreadPool.QueueUserWorkItem and it seems that thread started using ThreadPool will still keep executing even after Web Service returns response back to Web site. Am I correct

ThreadPool and sending emails

社会主义新天地 提交于 2019-12-05 06:55:32
问题 We are currently sending emails to users asynchronoulsy using the ThreadPool. Essentially, we have logic that comes down to this: for (int i=0 < i < numUsers; i++) { //Pre email processing unrelated to sending email string subject = GetSubject(); string message = GetMessage(); string emailAddress = GetEmailAddress(); EmailObj emailObj = new EmailObj { subject = subject, message = message, emailAddress = emailAddress }; bool sent = ThreadPool.QueueUserWorkItem(new WaitCallback(SendEmail),

Thread keeps running even after application has been stopped in Websphere

空扰寡人 提交于 2019-12-05 05:42:20
I have a long running thread which is created using org.springframework.scheduling.commonj.WorkManagerTaskExecutor with Spring and is running in Websphere Application Server 8. The problem is that this thread keeps running even if the application has been stopped. That thread needs to be stopped too but it is not happening. I even tried to use Thread.currentThread().isInterrupted() to check if the current thread was interrupted but it always returns false . So there is no way to know through my code if the Thread should keep running or stop. This is my spring configuration for the

ThreadPoolExecutor without a Queue

泪湿孤枕 提交于 2019-12-05 05:37:09
I want to create a fixed-size thread pool that admits no task into its queue. In other words, if the thread pool is currently in use, the incoming task should be rejected outright. Based on the documentation , one way to do this, in my opinion, would be to create a dummy Queue object which refuses to admit a task. What is the idiomatic way to accomplish this in Java? You can use a SynchronousQueue in your ThreadPoolExector which is a queue which holds no objects. The cached thread pool uses this because it creates new threads on demand. If it cannot be queued but I would suggest using the

Stopping processes in ThreadPool in Python

时光总嘲笑我的痴心妄想 提交于 2019-12-05 05:07:23
I've been trying to write an interactive wrapper (for use in ipython) for a library that controls some hardware. Some calls are heavy on the IO so it makes sense to carry out the tasks in parallel. Using a ThreadPool (almost) works nicely: from multiprocessing.pool import ThreadPool class hardware(): def __init__(IPaddress): connect_to_hardware(IPaddress) def some_long_task_to_hardware(wtime): wait(wtime) result = 'blah' return result pool = ThreadPool(processes=4) Threads=[] h=[hardware(IP1),hardware(IP2),hardware(IP3),hardware(IP4)] for tt in range(4): task=pool.apply_async(h[tt].some_long

Use Python pool.map to have multiple processes perform operations on a list

只愿长相守 提交于 2019-12-05 03:07:32
问题 I'm trying to start 6 threads each taking an item from the list files, removing it, then printing the value. from multiprocessing import Pool files = ['a','b','c','d','e','f'] def convert(file): process_file = files.pop() print process_file if __name__ == '__main__': pool = Pool(processes=6) pool.map(convert,range(6)) The expected output should be: a b c d e f Instead, the output is: f f f f f f What's going on? Thanks in advance. 回答1: Part of the issue is that you are not dealing with the