threadpool

Why should I prefer using API async fucntions over wrapping synchronous ones with Task.Run?

别等时光非礼了梦想. 提交于 2019-12-11 04:45:51
问题 I know there is a difference between this code: var streamWriter = new StreamWriter("something.txt"); streamWriter.WriteAsync("text"); and this: var streamWriter = new StreamWriter("something.txt"); Task.Run(()=> streamWriter.Write("text")); the first one makes much more sense. and in different scenario when I am awaiting a result, this code: var streamReader = new StreamReader("something.txt") char[] chars = new char[10]; Task<int> task = streamReader.ReadAsync(chars, 0, chars.Length); //Do

Effects of uncaught exceptions on threads from Quartz's SimpleThreadPool

戏子无情 提交于 2019-12-11 04:42:40
问题 Using Spring's integration api with Quartz , what will the effects be on cron jobs that have uncaught exceptions? Since the cronbean/worker thread did not catch the exception, will that mean the thread is dead and will not be able to go back to the SimpleThreadPool? If its dead and does not get back to the pool will that mean the SimpleThreadPool will need to create new threads, if say this happens multiple times thus emptying out the pool? This is a sample the stack trace: org

Glassfish set max number of concurrent Batch Jobs

≯℡__Kan透↙ 提交于 2019-12-11 04:07:33
问题 GlassFish allows you to tune the global EJB pool size, as well as specific pool sizes per EJB. By setting the max-pool-size under glassfish-ejb-jar.xml I can control how many instances of a EJB can be used in parallel. <glassfish-ejb-jar> <enterprise-beans> <ejb> <ejb-name>MyExpensiveEJB</ejb-name> <bean-pool> <max-pool-size>10</max-pool-size> </bean-pool> </ejb> </enterprise-beans> </glassfish-ejb-jar> I wonder if something similar can be done with the Java EE Batch API. I would like to

How can I catch InterruptedException when making http request with Apache?

点点圈 提交于 2019-12-11 03:43:54
问题 I have a Callable that makes a http request via Apache library. However, if the request takes too long, I would like to kill the thread. To do this, I can interrupt the Callable, but I need to catch the InterruptedException in order to stop myself. How can I do this? private final class HelloWorker implements Callable<String> { private String url; public HelloWorker(String url) { this.url = url; } public CloseableHttpResponse call() throws Exception { CloseableHttpClient httpClient =

Quit when QThreadPool not empty?

旧巷老猫 提交于 2019-12-11 03:28:03
问题 I have a lot of long running tasks that run in the background of my Python app. I put them all in the global QThreadPool . When the user quits, all of those background tasks need to stop. Right now, I have the following code: app.aboutToQuit.connect(killAllThreads) def killAllThreads(): QtCore.QThreadPool.globalInstance().waitForDone() I've seen suggestions to add a global variable that says whether the application should be quitting, and to have threads terminate themselves, but this sounds

C++ ThreadPool is not running parallel

不想你离开。 提交于 2019-12-11 03:26:56
问题 I've tried to implement a ThreadPool, but unfortunately I'm running into some problems. This is what I have already. //includes ... void call() { std::cout << "Hi i'm thread no " << std::this_thread::get_id() << std::endl; std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "ready " << std::this_thread::get_id() << std::endl; }; //Implementation is not shown here to reduce code class WorkQueue { public: bool push(std::function<void()> const& value); void pop(); bool empty(); };

Number of threads being used during Parallel.ForEach

耗尽温柔 提交于 2019-12-11 02:41:37
问题 I just did a simple experiment to show the total number of threads in a process using the code below. Console.WriteLine("Total Number of Threads: {0}", Process.GetCurrentProcess().Threads.Count); Parallel.ForEach( names, new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount }, name => { Console.WriteLine(name); }); Console.Read(); Console.WriteLine("Total Number of Threads: {0}", Process.GetCurrentProcess().Threads.Count); I got 12 threads before the parallel.foreach and

Access to singleton object from another thread

元气小坏坏 提交于 2019-12-11 02:25:01
问题 I call service method using ThreadPool.QueueUserWorkItem(o => service.Method(arg1, arg2)); Service has object 'loggingService' with I was get using Spring.Net private readonly ILoggingService loggingService = ObjectBuilder.GetObjectByName("LoggingService"); 'LoggingService' class is singleton. It writes log info to log.txt. When I try to call loggingService.Info("test") in this service method, I get exception: file is busy by another process. How can I access to the loggingService? 回答1: Your

Thread pool and execution queue in c++11

最后都变了- 提交于 2019-12-11 01:45:32
问题 I have a bunch of parallel tasks to complete, but only a few worker threads (say 8, but I want this to be configurable). So, 8 threads run, and each of the threads pops the next task from the queue, as long as the queue has tasks. Does C++11 provide any inbuilt constructs to help implement this design? I see some similar discussions related to std::async , but I think it leaves too much to the implementation of the compiler. 回答1: You can have std::vector<std::thread> if you want but the pool

Using lock statement with ThreadPool in C#

自作多情 提交于 2019-12-11 01:35:40
问题 I have a multi-threaded program (C#) where I have to share global static variables between threads that may take some time to execute (sending data request to another system using WCF). The problem is that using the lock statement does not seem to guarantee mutual exclusion when it's declared outside of the ThreadPool. static void Main(string[] args) { public static int globalVar = 0; public object locker; System.Timers.Timer timer1 = new System.Timers.Timer(1000); timer1.Elapsed += new