Replies: 1 comment 5 replies
-
private void configureCustomExecutor() {
// Create a custom thread pool
int corePoolSize = 4; // Core number of threads
int maximumPoolSize = 8; // Maximum number of threads
long keepAliveTime = 60L; // Keep-alive time for idle threads
TimeUnit unit = TimeUnit.SECONDS; // Time unit for keep-alive time
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(); // Unbounded work queue
// Custom thread factory (for naming threads)
ThreadFactory threadFactory = r -> {
Thread thread = new Thread(r);
thread.setName("custom-pool-thread-" + thread.getId()); // Set thread name
return thread;
};
// Rejection policy: run task in caller thread instead of rejecting
RejectedExecutionHandler handler = new ThreadPoolExecutor.CallerRunsPolicy();
// Create the custom thread pool
ExecutorService executorService = new ThreadPoolExecutor(
corePoolSize, maximumPoolSize, keepAliveTime, unit,
workQueue, threadFactory, handler
);
bind(ExecutorService.class)
.annotatedWith(CustomExecutor.class)
.toInstance(executorService);
bind(Executor.class)
.annotatedWith(CustomExecutor.class)
.toInstance(executorService);
// Create a scheduled thread pool for scheduled tasks
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
bind(ScheduledExecutorService.class)
.annotatedWith(CustomScheduledExecutor.class)
.toInstance(scheduler);
}
nd(ScheduledExecutorService.class)
.annotatedWith(CustomScheduledExecutor.class)
.toInstance(scheduler);
} |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, author. I’m feeling confused while using OpenTCS. I don’t understand how kernelExecutor works when restarting the map. It seems like kernelExecutor is being reset somehow. I created my own thread pool and want it to behave like kernelExecutor, but I’m not sure how to achieve that. I noticed there's a call to kernelExecutor.shutdown() in the code, but that doesn’t seem to be the correct place.
Beta Was this translation helpful? Give feedback.
All reactions