Support copying logging context to background threads
The logging context (contains logging tags) is stored in ThreadLocal variables. When we execute work in background threads we must propagate the logging context from the current thread to the background threads. Add a LoggingContextAwareThreadFactory that does this and use it in all places where we create new threads. Change-Id: I349f0a8b667266df1684ae5f5d8fb0bcae9aceaa Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.gerrit.server.FanOutExecutor;
|
||||
import com.google.gerrit.server.git.WorkQueue;
|
||||
import com.google.gerrit.server.logging.LoggingContextAwareThreadFactory;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -89,7 +90,11 @@ public class SysExecutorModule extends AbstractModule {
|
||||
10,
|
||||
TimeUnit.MINUTES,
|
||||
new ArrayBlockingQueue<Runnable>(poolSize),
|
||||
new ThreadFactoryBuilder().setNameFormat("ChangeUpdate-%d").setDaemon(true).build(),
|
||||
new ThreadFactoryBuilder()
|
||||
.setThreadFactory(new LoggingContextAwareThreadFactory())
|
||||
.setNameFormat("ChangeUpdate-%d")
|
||||
.setDaemon(true)
|
||||
.build(),
|
||||
new ThreadPoolExecutor.CallerRunsPolicy())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user