threadpool

Writing to the same file; not overwriting

十年热恋 提交于 2019-12-24 19:17:05
问题 Here is my snippet. File file = new File(Thread.currentThread().getName()); for(each element of the list){ createStringWriterAndPopulateDataToBeWritten FileOutputStream fo = new FileOutputStream(file); OutputStreamWriter out = new OutputStreamWriter(fo,"UTF-8"); out.write(sw.toString()); out.close(); } Now say i have a newFixedThreadPool of size S ; i pass this thread pool a list of work to be done. Now everytime a thread is called, it creates a file with name as the name of thread and then

Invalid conversion from `void *` to `void (*)(void*)`

落花浮王杯 提交于 2019-12-24 18:45:27
问题 So I'm currently using, or at least trying to write a program that makes use of this C pthread threadpool library. Of note is the following function in thpool.h : int thpool_add_work(threadpool, void (*function_p)(void*), void* arg_p); My code which I'm trying to add a work to is as follows: int testpool(string (&input)[3]){ // Pass three strings to it. Which we will end up displaying. cout << input[0].c_str() << endl; cout << input[1].c_str() << endl; cout << input[2].c_str() << endl; return

how to enhance tomcat thread pool behaviour

你说的曾经没有我的故事 提交于 2019-12-24 17:43:27
问题 I'm running the java application using tomcat7. I need to store the information per tomcat thread, so I can use the ThreadLocals approach. In my server.xml the threadpool definition looks like the following: <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="10000" minSpareThreads="2000"/> I have a class EnhanceThread public class EnhanceThread extends Thread { ... @Override public void run() { SomeThreadLocals.set(data); super.run(); } } How can I override the tomcat

Java Thread Pool Throughput

試著忘記壹切 提交于 2019-12-24 17:08:13
问题 I am observing a very strange problem in a java client server application. I am sending following Runnable objects to the server at 80 requests per second. The thread pool keeps pool size equal to the request rate i.e. approximately 80 threads in the pool. My laptop is intel Core i5-3230M dual core(Windows show me 4 processor). Strange thing is that the Throughput(jos completed per second) is also 80. I could not understand this. How 4 processors and 80 threads are completing 80 jobs of 100

Port scanning using threadpool

女生的网名这么多〃 提交于 2019-12-24 16:18:34
问题 I am trying to run a small app that scans ports and checks to see if they are open using and practicing with threadpools. The console window will ask a number and scans ports from 1 to X and will display each port whether they are open or closed. My problem is that as it goes through each port, it sometimes stops prematurely. It doesn't stop at just one number either, its pretty random. For example it I specify 200. The console will scroll through each port then stops at 110. Next time I run

How to choose thread pool size?

大憨熊 提交于 2019-12-24 12:24:35
问题 Suppose I have to read, process and update a lot of files in Java. I am going to use one computer with 16 cores. Since I have both IO-bound (read and update files) and CPU-bound (processing) tasks I allocate 2 thread pools. I would allocate one pool for CPU-bound tasks with 16 threads (the number of threads == the number of CPUs). Now I wonder what the IO-bound pool size is. Thread pools of what sizes would you suggest ? 回答1: It would depend on your storage capabilities and what kinds of IO

Can't submit callble objects that return void to a thread pool, but only callable objects that returns values

♀尐吖头ヾ 提交于 2019-12-24 11:38:02
问题 I'm working on a thread pool from the book C++ Cuncerrency in Action by Anthony Willimas This thread pools has a submit call that take as tasks callable objects that return a value and return a std::future handle to them, and I managed to build applications that use it. But I can't manage to make it work with callable ojects that return void: the code won't even compile. I get these errors, all in the future header : error C2182: '_Get_value' : illegal use of type 'void' error C2182: '_Val' :

TPL - set Task to Thread.Sleep for a long time

自古美人都是妖i 提交于 2019-12-24 11:06:24
问题 I have a test to use .NET Task Parallel Library: static void Main(string[] args) { for(int i = 0; i < 1000; i++) { int n = i; Task.Factory.StartNew(() => TaskTest(n)); } } static void TaskTest(int i) { // Will sleep for a long time Thread.Sleep(TimeSpan.FromMinutes(i)); // Do something here } One thing I'm not sure: When Thread.Sleep in the above code execute, what will happen? I know it will not occupy a thread in the ThreadPool, is there any drawback if I set multiple tasks to Thread.Sleep

Thread vs ThreadPool - .Net 2.0

谁都会走 提交于 2019-12-24 10:57:33
问题 I'm not able to understand the difference between Thread vs ThreadPool. Consider i've to manipulate 50,000 records using threads. In case of threads i need to either predefine no of threads or no of records per threads. Either of them has to be constant. In case of threadpool we dont need to set any of them theoretically. But practically we need to assign the number of records per thread, because the no of threads may grow extremely large if the input no of records is huge. Any insights on

Cost of RunSynchronously

ⅰ亾dé卋堺 提交于 2019-12-24 10:44:38
问题 What are the reasons why the two timings below differs so dramatically ? let time acquire = let sw = System.Diagnostics.Stopwatch.StartNew() sw.Start() let tsks = [1 .. 10] |> Seq.map (fun x -> acquire) let sec = Async.RunSynchronously(Async.Parallel tsks) sw.Stop() printfn "Generation time %A ms" sw.Elapsed.TotalMilliseconds sw.Reset() Console.ReadKey() |> ignore let custPool = ObjectPool(customerGenerator, 0) let acquire = async { printfn "acquiring cust" ; return! custPool.Get() } let