Package io.objectbox

Class ObjectBoxThreadPoolExecutor

All Implemented Interfaces:
Executor, ExecutorService

public class ObjectBoxThreadPoolExecutor extends ThreadPoolExecutor
A ThreadPoolExecutor that automatically releases thread-local ObjectBox resources after each task execution by calling BoxStore.closeThreadResources().

This is useful when using a thread pool with ObjectBox to ensure that thread-local resources (currently readers only) are properly cleaned up after each task completes.

Recommended: Use the factory methods BoxStore.newFixedThreadPoolExecutor(int) or BoxStore.newCachedThreadPoolExecutor() to create instances of this executor.

Example usage:

 BoxStore boxStore = MyObjectBox.builder().build();

 // Recommended: Use BoxStore factory methods
 ObjectBoxThreadPoolExecutor executor = boxStore.newFixedThreadPoolExecutor(4);

 // Or for a cached thread pool
 ObjectBoxThreadPoolExecutor cachedExecutor = boxStore.newCachedThreadPoolExecutor();

 // Advanced: Direct construction for custom configuration
 ObjectBoxThreadPoolExecutor customExecutor = new ObjectBoxThreadPoolExecutor(
     boxStore,
     4, // core pool size
     8, // maximum pool size
     60L, TimeUnit.SECONDS, // keep-alive time
     new LinkedBlockingQueue<>()
 );