threadpool

Threads within threads in Java?

末鹿安然 提交于 2019-11-26 21:19:44
问题 I am currently thinking about how to design a multithreading system in Java that needs to do some heavy network processing and database storage. The program will launch three basic threads at first. Along these basic threads, I would like to launch other threads not from the main program but from two of the threads. Is it possible for a thread to launch another thread leading to some sort of a hierarchy like: > Parent ->t0 thread1 -> t1 tread1.1 > ->t0 thread2 > ->t0 thread3 -> t2 thread3.1

C# Downloader: should I use Threads, BackgroundWorker or ThreadPool?

谁说胖子不能爱 提交于 2019-11-26 20:21:40
问题 I'm writing a downloader in C# and stopped at the following problem: what kind of method should I use to parallelize my downloads and update my GUI? In my first attempt, I used 4 Threads and at the completion of each of them I started another one: main problem was that my cpu goes 100% at each new thread start. Googling around, I found the existence of BackgroundWorker and ThreadPool: stating that I want to update my GUI with the progress of each link that I'm downloading, what is the best

Using boost::asio thread pool for general purpose tasks

拟墨画扇 提交于 2019-11-26 20:15:35
问题 In this blog I found a pretty neat example on how to create a simple thread pool using boost::asio. I basically want to use it like this: #include <thread> #include <functional> #include <boost/asio.hpp> int main ( int argc, char* argv[] ) { asio::io_service io_service; asio::io_service::work work(io_service); std::vector<std::thread> threadPool; for(size_t t = 0; t < std::thread::hardware_concurrency(); t++){ threadPool.push_back(thread(std::bind(&asio::io_service::run, &io_service))); } io

Is it true that for long running processes it is better to do thread manually instead of threadpool?

放肆的年华 提交于 2019-11-26 20:13:45
问题 I read on the other day that for long-running tasks my best bet is to manually create threads instead of using .NET’s thread pool or Task Parallel. I'd really like someone to enlighten me as I am learning about c# threading, specially for long running IO tasks. Thank you in advance. 回答1: That is true. The thread pool is optimised for small units of work and you can interfere with other work by holding onto a thread pool thread. My rule of thumb is if an operation can take more than a second,

Propagating ThreadLocal to a new Thread fetched from a ExecutorService

佐手、 提交于 2019-11-26 19:14:58
问题 I'm running a process in a separate thread with a timeout, using an ExecutorService and a Future (example code here) (the thread "spawning" takes place in a AOP Aspect). Now, the main thread is a Resteasy request. Resteasy uses one ore more ThreadLocal variables to store some context information that I need to retrieve at some point in my Rest method call. Problem is, since the Resteasy thread is running in a new thread, the ThreadLocal variables are lost. What would be the best way to

Why does Windows 10 start extra threads in my program?

孤街醉人 提交于 2019-11-26 19:00:48
With Visual Studio 2015, in a new, empty C++ project, build the following for Console application: int main() { return 0; } Set a break point on the return and launch the program in the debugger. On Windows 7, as of the break point, this program has only one thread. But on Windows 10, it has five(!) threads: the main thread and four "worker threads" waiting on a synchronization object. Who's starting up the thread pool (or how do I find out)? Crystal ball says that the Debug > Windows > Threads window shows these threads at ntdll.dll!TppWorkerThread . Be sure to enable the Microsoft Symbol

What is the use of a Thread pool in Java?

怎甘沉沦 提交于 2019-11-26 18:55:16
问题 What is the use of a Thread pool? Is there a good real world example? 回答1: A thread pool is a group of threads initially created that waits for jobs and executes them. The idea is to have the threads always existing, so that we won't have to pay overhead time for creating them every time. They are appropriate when we know there's a stream of jobs to process, even though there could be some time when there are no jobs. Here's a nice diagram from Wikipedia: 回答2: Thread Pools from the Java

Where do I create and use ScheduledThreadPoolExecutor, TimerTask, or Handler?

穿精又带淫゛_ 提交于 2019-11-26 18:42:17
I need to make my RSS Feed reader check the feed every 10 minutes for new posts, and then parse them if there are new ones. I also need to update the UI about every minute. I have read and heard different things from various sources. My current understanding is that I can use ScheduledThreadPoolExecutor to make two scheduled threads, and one of them needs a Handler for updating the UI. I am unsure about what the most efficient use of these classes or TimerTask . I am also very uncertain about where to make subclasses of these. One friend suggested extending TimerTask as an inner class in my

Turning an ExecutorService to daemon in Java

旧街凉风 提交于 2019-11-26 18:41:18
I am using an ExecutoreService in Java 1.6, started simply by ExecutorService pool = Executors.newFixedThreadPool(THREADS). When my main thread is finished (along with all the tasks processed by the thread pool), this pool will prevent my program from shutting down until I explicitly call pool.shutdown(); Can I avoid having to call this by somehow turning the internal thread managing used by this pool into a deamon thread? Or am I missing something here. Probably simplest and preferred solution is in Marco13's answer so don't get fooled by vote difference (mine answer is few years older) or

Can somebody explain this odd behavior when working with ThreadPool?

孤者浪人 提交于 2019-11-26 18:37:01
问题 The Code using System; using System.Threading; public delegate void LoadingProgressCallback(double PercentComplete,string ItemName); public delegate void LoadCompleteCallback(int ItemID, string ItemName); public static class Program { public static void Main(string[] args) { LoadTest loadTest = new LoadTest(); loadTest.LoadItems(args); } } public class LoadTest { ManualResetEvent resetEvent; int numThreads = 0; public LoadTest() {} public void LoadItems(string[] Items) { numThreads = 0;