Added ThreadNameCallable and ThreadNameRunnable for scenarios when code needs to set the thread name during the execution of the Callable or Runnable, for correlation/logging purposes, but wants to revert the thread name to the original version after execution.
Example Scenario
The current thread name is carrierThread
The thread name needs to reflect the work being performed for correlation/logging purposes
The thread name needs to be carrierThread/task1 when executing task 1
The thread name needs to be carrierThread/task2 when executing task 2
Example Code
String threadName = Thread.currentThread().getName();
ExecutorService executorService = ExecutorTool.newVirtualThreadPerTaskExecutor();
executorService.submit(
new NamedRunnable(
threadName + "/customRunnable1", new CustomRunnable1());
executorService.submit(
new NamedRunnable(
threadName + "/customRunnable2", new CustomRunnable2());
Summary
Added
ThreadNameCallable
andThreadNameRunnable
for scenarios when code needs to set the thread name during the execution of theCallable
orRunnable
, for correlation/logging purposes, but wants to revert the thread name to the original version after execution.Example Scenario
carrierThread
carrierThread/task1
when executing task 1carrierThread/task2
when executing task 2Example Code