threadpool

JAVAFX : why wait cursor needs a new thread?

折月煮酒 提交于 2019-11-26 18:34:20
问题 I would understand why scene.setCursor(Cursor.WAIT); long task... scene.setCursor(Cursor.DEFAULT); needs new threads; it works with: private void set_cursore_attesa(final Scene scene) { Runnable r=new Runnable() { @Override public void run() { scene.setCursor(Cursor.WAIT); } }; Thread t=new Thread(r); t.start(); } private void set_cursore_normale(final Scene scene) { Runnable r=new Runnable() { @Override public void run() { scene.setCursor(Cursor.DEFAULT); } }; Thread t=new Thread(r); t.start

Dynamic Thread Pool

瘦欲@ 提交于 2019-11-26 18:33:53
问题 I have a long running process that listens to events and do some intense processing. Currently I use Executors.newFixedThreadPool(x) to throttle the number of jobs that runs concurrently, but depending of the time of the day, and other various factors, I would like to be able to dynamically increase or decrease the number of concurrent threads. If I decrease the number of concurrent threads, I want the current running jobs to finish nicely. Is there a Java library that let me control and

What is optimum thread pool size for simple program running cpu based tasks in Java

做~自己de王妃 提交于 2019-11-26 18:19:19
问题 Im using a thread pool to execute tasks , that are mostly cpu based with a bit of I/O, of size one larger than the number of cpus. Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1) Assuming case of simple program that submits all its tasks to this executor and does little else I assume having a thread pool any larger would slow things because the OS would have to timeslice it cpus more often chance to give each thread in the threadpool a chance to run. Is that

WaitAll for multiple handles on a STA thread is not supported

老子叫甜甜 提交于 2019-11-26 18:12:52
问题 Why do I get this error message? "WaitAll for multiple handles on a STA thread is not supported." Should I use [MTAThreadAttribute] attribut? Update: Dosn't work with WPF applications! Note: It error is at line WaitHandle.WaitAll(doneEvents); I'm using a standard WPF project . private void Search() { const int CPUs = 2; var doneEvents = new ManualResetEvent[CPUs]; // Configure and launch threads using ThreadPool: for (int i = 0; i < CPUs; i++) { doneEvents[i] = new ManualResetEvent(false);

What determines the number of threads a Java ForkJoinPool creates?

蓝咒 提交于 2019-11-26 18:05:37
问题 As far as I had understood ForkJoinPool , that pool creates a fixed number of threads (default: number of cores) and will never create more threads (unless the application indicates a need for those by using managedBlock ). However, using ForkJoinPool.getPoolSize() I discovered that in a program that creates 30,000 tasks ( RecursiveAction ), the ForkJoinPool executing those tasks uses 700 threads on average (threads counted each time a task is created). The tasks don't do I/O, but pure

C# thread pool limiting threads

瘦欲@ 提交于 2019-11-26 18:00:54
问题 Alright...I've given the site a fair search and have read over many posts about this topic. I found this question: Code for a simple thread pool in C# especially helpful. However, as it always seems, what I need varies slightly. I have looked over the MSDN example and adapted it to my needs somewhat. The example I refer to is here: http://msdn.microsoft.com/en-us/library/3dasc8as(VS.80,printer).aspx My issue is this. I have a fairly simple set of code that loads a web page via the

When to use thread pool in C#? [closed]

孤街浪徒 提交于 2019-11-26 17:01:43
I have been trying to learn multi-threaded programming in C# and I am confused about when it is best to use a thread pool vs. create my own threads. One book recommends using a thread pool for small tasks only (whatever that means), but I can't seem to find any real guidelines. What are some considerations you use when making this programming decision? Robert Gould If you have lots of logical tasks that require constant processing and you want that to be done in parallel use the pool+scheduler. If you need to make your IO related tasks concurrently such as downloading stuff from remote servers

Thread/threadpool or backgroundworker

拥有回忆 提交于 2019-11-26 16:29:55
问题 I would like to know what to use for tasks that need alot of performance. Backgroundworker , Thread or ThreadPool ? I've been working with Threads so far, but I need to improve speed of my applications. 回答1: BackgroundWorker is the same thing as a thread pool thread. It adds the ability to run events on the UI thread. Very useful to show progress and to update the UI with the result. So its typical usage is to prevent the UI from freezing when works needs to be done. Performance is not the

Removing all queued tasks of an ThreadPoolExecutor

天大地大妈咪最大 提交于 2019-11-26 16:23:08
问题 i have this rather simple question about the ThreadPoolExecutor. I have the following situation: I have to consume objects from a queue, create the appropiate worker tasks for them and submit them to the ThreadPoolExecutor. This is quite simple. But within a shutdown scenario many workers may be queued to execution. Since one of those tasks might be running for an hour, and i want a relativly fast graceful shutdown of the application i want to discard all queued tasks from the

Wait for QueueUserWorkItem to Complete

无人久伴 提交于 2019-11-26 15:58:23
问题 If I add jobs to the thread pool with QueueUserWorkItem ... how do I keep my program from going forward until all jobs are completed? I know I could add some logic to keep the app from running until all jobs are completed, but I want to know if there is something like Thread.Join() or if there's any way to retrieve each thread that is being assigned a job. 回答1: You could use events to sync. Like this: private static ManualResetEvent resetEvent = new ManualResetEvent(false); public static void