Code for a simple thread pool in C# [closed]

This is the simplest, naive, thread-pool implementation for educational purposes I could come up with (C# / .NET 3.5). It is not using the .NET’s thread pool implementation in any way. using System; using System.Collections.Generic; using System.Threading; namespace SimpleThreadPool { public sealed class Pool : IDisposable { public Pool(int size) { this._workers = new LinkedList<Thread>(); … Read more

How to create a thread pool using boost in C++?

The process is pretty simple. First create an asio::io_service and a thread_group. Fill the thread_group with threads linked to the io_service. Assign tasks to the threads using the boost::bind function. To stop the threads (usually when you are exiting your program) just stop the io_service and join all threads. You should only need these headers: … Read more

C# – ThreadPool vs Tasks

The objective of the Tasks namespace is to provide a pluggable architecture to make multi-tasking applications easier to write and more flexible. The implementation uses a TaskScheduler object to control the handling of tasks. This has virtual methods that you can override to create your own task handling. Methods include for instance protected virtual void … Read more

How to configure a fine tuned thread pool for futures?

This answer is from monkjack, a comment from the accepted answer. However, one can miss this great answer so I’m reposting it here. implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10)) If you just need to change the thread pool count, just use the global executor and pass the following system properties. -Dscala.concurrent.context.numThreads=8 -Dscala.concurrent.context.maxThreads=8

ThreadPool.QueueUserWorkItem vs Task.Factory.StartNew

If you’re going to start a long-running task with TPL, you should specify TaskCreationOptions.LongRunning, which will mean it doesn’t schedule it on the thread-pool. (EDIT: As noted in comments, this is a scheduler-specific decision, and isn’t a hard and fast guarantee, but I’d hope that any sensible production scheduler would avoid scheduling long-running tasks on … Read more

Should i use ThreadPools or Task Parallel Library for IO-bound operations

So i instead decided to write tests for this and see it on practical data. Test Legend Itr: Iteration Seq: Sequential Approach. PrlEx: Parallel Extensions – Parallel.ForEach TPL: Task Parallel Library TPool: ThreadPool Test Results Single-Core CPU [Win7-32] — runs under VMWare — Test Environment: 1 physical cpus, 1 cores, 1 logical cpus. Will be … Read more

Turning an ExecutorService to daemon in Java

Probably simplest and preferred solution is in Marco13’s answer so don’t get fooled by vote difference (this answer is few years older) or acceptance mark (it just means that this solution was appropriate for OP circumstances, not that it is best in general). You can use ThreadFactory to set threads inside Executor to daemons. This … Read more

Java: ExecutorService that blocks on submission after a certain queue size [duplicate]

I have done this same thing. The trick is to create a BlockingQueue where the offer() method is really a put(). (you can use whatever base BlockingQueue impl you want). public class LimitedQueue<E> extends LinkedBlockingQueue<E> { public LimitedQueue(int maxSize) { super(maxSize); } @Override public boolean offer(E e) { // turn offer() and add() into a … Read more

What’s the difference between ThreadPool vs Pool in the multiprocessing module?

The multiprocessing.pool.ThreadPool behaves the same as the multiprocessing.Pool with the only difference that uses threads instead of processes to run the workers logic. The reason you see hi outside of main() being printed multiple times with the multiprocessing.Pool is due to the fact that the pool will spawn 5 independent processes. Each process will initialize … Read more

Maximum (client request) thread pool size in spring

Assuming that you’re using embedded Tomcat, Spring Boot uses the server.tomcat.max-threads property to control the size of the client request thread pool. Its default value is zero which leaves Tomcat to use its default of 200. To customise the size of this thread pool you should specify a non-zero value for the server.tomcat.max-threads property in … Read more