WorkQueue: Don't lazy-initialize the default queue

The default queue is used in several places and is initialized during
the server start-up, so the lazy initialization doesn't win much.

Moving the initialization into the constructor means we can mark the
queue as final, and don't need to keep the default queue size value as
a member.

The getDefaultQueue no longer needs to be synchronized, since there is
no longer any chance of racing to create the queue.

Change-Id: Ib880e3b9caf79718865944ec88c3337d0080e2c3
This commit is contained in:
David Pursehouse
2018-05-07 21:01:13 +09:00
parent 97b615fc51
commit 9c1a6a012e

View File

@@ -82,8 +82,7 @@ public class WorkQueue {
}
};
private Executor defaultQueue;
private final int defaultQueueSize;
private final Executor defaultQueue;
private final IdGenerator idGenerator;
private final CopyOnWriteArrayList<Executor> queues;
@@ -96,14 +95,11 @@ public class WorkQueue {
public WorkQueue(IdGenerator idGenerator, int defaultThreadPoolSize) {
this.idGenerator = idGenerator;
this.queues = new CopyOnWriteArrayList<>();
this.defaultQueueSize = defaultThreadPoolSize;
this.defaultQueue = createQueue(defaultThreadPoolSize, "WorkQueue");
}
/** Get the default work queue, for miscellaneous tasks. */
public synchronized Executor getDefaultQueue() {
if (defaultQueue == null) {
defaultQueue = createQueue(defaultQueueSize, "WorkQueue");
}
public Executor getDefaultQueue() {
return defaultQueue;
}