ExecutorService 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ExecutorService --version 0.4.0
                    
NuGet\Install-Package ExecutorService -Version 0.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ExecutorService" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ExecutorService" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="ExecutorService" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ExecutorService --version 0.4.0
                    
#r "nuget: ExecutorService, 0.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ExecutorService@0.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ExecutorService&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=ExecutorService&version=0.4.0
                    
Install as a Cake Tool

ExecutorService

CI NuGet NuGet Downloads License: MIT

A .NET port of Java's java.util.concurrent.ExecutorService: bounded executors backed by dedicated threads, an explicit lifecycle (Shutdown, ShutdownNow, AwaitTermination), and Task-based futures.

Why?

The .NET ThreadPool is a single, process-wide, elastic pool. That is the right default for async I/O, but sometimes you want what Java developers reach for with Executors.newFixedThreadPool(n):

  • A fixed number of threads for a specific workload, isolated from the rest of the process.
  • Safe blocking work without starving the shared pool.
  • A deterministic shutdown: stop accepting work, drain or drop the queue, wait for termination.
  • Strict FIFO and, with one thread, strictly sequential execution.

Installation

dotnet add package ExecutorService

Requires .NET 10 or later.

Quick start

using ExecutorService;

using IExecutorService executor = Executors.NewFixedThreadPool(4);

// Fire and forget
executor.Execute(() => Console.WriteLine("hello from a pool thread"));

// Submit and await a result
Task<int> future = executor.Submit(() => ComputeSomethingExpensive());
int result = await future;

// Orderly shutdown: finish queued work, reject new work
executor.Shutdown();
bool terminated = executor.AwaitTermination(TimeSpan.FromSeconds(10));

Disposing the executor is equivalent to Java's close(): it calls Shutdown() and waits for termination. await using does the same without blocking.

Dropping pending work

IReadOnlyList<Task> neverStarted = executor.ShutdownNow();
// each Task in `neverStarted` is in the Canceled state

Tasks that are already running are not interrupted. .NET has no thread interruption; implement cooperative cancellation inside your task if you need it.

Configuring worker threads

var executor = Executors.NewFixedThreadPool(2, new ThreadPoolExecutorOptions
{
    ThreadNamePrefix = "image-resizer",   // threads are named image-resizer-0, image-resizer-1
    IsBackground = false,                 // keep the process alive while work is pending
    Priority = ThreadPriority.BelowNormal,
});

Java to .NET mapping

Java ExecutorService (.NET)
Executor IExecutor
ExecutorService IExecutorService
Executors.newFixedThreadPool(n) Executors.NewFixedThreadPool(n)
Executors.newSingleThreadExecutor() Executors.NewSingleThreadExecutor()
execute(Runnable) Execute(Action)
submit(Runnable) / submit(Callable) Submit(Action) / Submit<T>(Func<T>)
Future<T> Task<T>
shutdown() / shutdownNow() Shutdown() / ShutdownNow()
awaitTermination(timeout, unit) AwaitTermination(TimeSpan) / AwaitTerminationAsync(TimeSpan, CancellationToken)
isShutdown() / isTerminated() IsShutdown / IsTerminated
close() Dispose() / DisposeAsync()
RejectedExecutionException RejectedExecutionException

Roadmap

See CHANGELOG.md for released features. Planned:

  • InvokeAll / InvokeAny
  • Cancellation-aware overloads (Func<CancellationToken, T>) and ShutdownNow propagating a token
  • Async task overloads (Func<Task>, Func<Task<T>>)
  • Bounded queues with rejection policies (Abort, CallerRuns, Discard, DiscardOldest)
  • Executors.NewCachedThreadPool() with core / max pool size and keep-alive
  • IScheduledExecutorService (Schedule, ScheduleAtFixedRate, ScheduleWithFixedDelay)
  • TaskScheduler adapter so Task.Factory.StartNew can target an executor

Contributing

Contributions are welcome. Please read CONTRIBUTING.md and the Code of Conduct.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.7.3 55 9/26/2026
0.7.2 156 9/7/2026
0.7.1 128 9/5/2026
0.7.0 167 9/5/2026
0.6.2 125 9/5/2026
0.6.1 93 9/5/2026
0.6.0 97 9/4/2026
0.5.1 85 9/4/2026
0.5.0 93 9/4/2026
0.4.0 91 9/3/2026
0.3.0 91 9/3/2026
0.2.0 100 9/3/2026