threadpool

PerThreadLifetimeManager in Unity

懵懂的女人 提交于 2019-12-22 12:37:40
问题 In the Unity PerThreadLifetimeManager documentation, I read that: " This lifetime manager does not dispose the instances it holds ". Ref.: http://msdn.microsoft.com/en-us/library/ff647854.aspx So, if I am using a ThreadPool, does it mean that objects resolved using Unity on a Thread of the ThreadPool will not get disposed at the end of the work done in that thread before being returned to the pool? Any pattern or ideas how I can ensure that the objects do get disposed & I get a clean thread

Java: notify main class when all threads in threadpool are finished / same instance of object in different threads

不羁岁月 提交于 2019-12-22 11:12:35
问题 How do I notify my main class which instantiates a ThreadPoolExecutor when all threads within the ThreadPoolExecutor are completed? ThreadPoolExecutor threadPool = null; ThreadClass threadclass1; ThreadClass threadclass2; final ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(maxPoolSize); puclic MyClass(){ threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue); threadClass1 = new ThreadClass; threadClass2 = new ThreadClass;

Python multiprocessing pool stuck

。_饼干妹妹 提交于 2019-12-22 08:19:12
问题 I'm trying to run some sample code of the multiprocessing.pool module of python, found in the web. The code is: def square(x): return x * x if __name__ == '__main__': pool = Pool(processes=4) inputs = [0, 1, 2, 3, 4] outputs = pool.map(square, inputs) But when i try to run it, it never finsh the execution and i have to restart the kernel of my IpythonNotebook notebook. What's the problem? 回答1: As you may read from the answer pointed out by John in the comments, multiprocessing.Pool , in

.NET threading like Node.js/V8?

我只是一个虾纸丫 提交于 2019-12-22 07:08:44
问题 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

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

一曲冷凌霜 提交于 2019-12-22 05:18:47
问题 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

Stopping processes in ThreadPool in Python

怎甘沉沦 提交于 2019-12-22 04:42:19
问题 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)

Thread creation in JavaEE EJB/Web containers

痴心易碎 提交于 2019-12-21 22:01:49
问题 I read in Adam Bien's JavaEE night hacks book that while thread creation is prohibited on EJB containers, this is not the case for web containers. He actually creates a thread pool executor in his x-ray probe which runs on Tomcat. I'm a little confused now. While I faced situations in which I had to do manual thread-pool management in an EE app, I can somehow understand why it would be a bad idea to manually create threads in a JavaEE container. However, I don't understand the difference

Thread creation in JavaEE EJB/Web containers

故事扮演 提交于 2019-12-21 21:51:03
问题 I read in Adam Bien's JavaEE night hacks book that while thread creation is prohibited on EJB containers, this is not the case for web containers. He actually creates a thread pool executor in his x-ray probe which runs on Tomcat. I'm a little confused now. While I faced situations in which I had to do manual thread-pool management in an EE app, I can somehow understand why it would be a bad idea to manually create threads in a JavaEE container. However, I don't understand the difference

Using ThreadPool within loops in C#

烂漫一生 提交于 2019-12-21 17:58:07
问题 I'm not too clued up with threading but is the following code acceptable (I'm more worried about using thread pools within a loop): string[] filePaths = GetFilePaths(); foreach (string filePath in filePaths ) { ThreadPool.QueueUserWorkItem(DoStuff, filePath); } Is there any other way that this can be done? EDIT: N.B. Each execution of DoStuff will in turn create multiple sub threads (about 200). These sub-threads simulate users of the system and is only responsible for receiving and sending

Asynchronous socket reading: the initiating thread must not be exited - what to do?

狂风中的少年 提交于 2019-12-21 12:46:07
问题 I have a NetworkStream which I read asynchronously (using async/await) await Task<int>.Factory.FromAsync((cb, state) => stream.BeginRead(buffer, offset, readLen - offset), stream.EndRead, null); Unfortunatly, an io exception sometimes occurs: "The I/O operation has been aborted because of either a thread exit or an application request." I believe I hit a requirement documented in Socke.EndReceive: http://msdn.microsoft.com/en-us/library/w7wtt64b.aspx . Which states: All I/O initiated by a