Skip to content

Commit d6d70d1

Browse files
nurkiewiczrozza
authored andcommitted
Named thread pools (mongodb#387)
JAVA-2458
1 parent 1613f0f commit d6d70d1

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

driver-core/src/main/com/mongodb/connection/DefaultConnectionPool.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656

5757
class DefaultConnectionPool implements ConnectionPool {
5858
private static final Logger LOGGER = Loggers.getLogger("connection");
59-
private static final DaemonThreadFactory THREAD_FACTORY = new DaemonThreadFactory();
6059

6160
private final ConcurrentPool<UsageTrackingInternalConnection> pool;
6261
private final ConnectionPoolSettings settings;
@@ -77,7 +76,7 @@ class DefaultConnectionPool implements ConnectionPool {
7776
= new UsageTrackingInternalConnectionItemFactory(internalConnectionFactory);
7877
pool = new ConcurrentPool<UsageTrackingInternalConnection>(settings.getMaxSize(), connectionItemFactory);
7978
maintenanceTask = createMaintenanceTask();
80-
sizeMaintenanceTimer = createTimer();
79+
sizeMaintenanceTimer = createMaintenanceTimer();
8180
this.connectionPoolListener = notNull("connectionPoolListener", connectionPoolListener);
8281
connectionPoolListener.connectionPoolOpened(new ConnectionPoolOpenedEvent(serverId, settings));
8382
}
@@ -214,7 +213,7 @@ public void onResult(final Void result, final Throwable t) {
214213

215214
private synchronized ExecutorService getAsyncGetter() {
216215
if (asyncGetter == null) {
217-
asyncGetter = Executors.newSingleThreadExecutor(THREAD_FACTORY);
216+
asyncGetter = Executors.newSingleThreadExecutor(new DaemonThreadFactory("AsyncGetter"));
218217
}
219218
return asyncGetter;
220219
}
@@ -311,11 +310,11 @@ public synchronized void run() {
311310
return newMaintenanceTask;
312311
}
313312

314-
private ExecutorService createTimer() {
313+
private ExecutorService createMaintenanceTimer() {
315314
if (maintenanceTask == null) {
316315
return null;
317316
} else {
318-
ScheduledExecutorService newTimer = Executors.newSingleThreadScheduledExecutor(THREAD_FACTORY);
317+
ScheduledExecutorService newTimer = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory("MaintenanceTimer"));
319318
newTimer.scheduleAtFixedRate(maintenanceTask, settings.getMaintenanceInitialDelay(MILLISECONDS),
320319
settings.getMaintenanceFrequency(MILLISECONDS), MILLISECONDS);
321320
return newTimer;

driver-core/src/main/com/mongodb/internal/thread/DaemonThreadFactory.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ public class DaemonThreadFactory implements ThreadFactory {
3131
private final AtomicInteger threadNumber = new AtomicInteger(1);
3232
private final String namePrefix;
3333

34-
public DaemonThreadFactory() {
35-
this("pool");
36-
}
37-
3834
public DaemonThreadFactory(final String prefix) {
3935
namePrefix = prefix + "-" + POOL_NUMBER.getAndIncrement() + "-thread-";
4036
}

driver/src/main/com/mongodb/Mongo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ <T> T execute(final WriteOperation<T> operation) {
849849
}
850850

851851
private ExecutorService createCursorCleaningService() {
852-
ScheduledExecutorService newTimer = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory());
852+
ScheduledExecutorService newTimer = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory("CleanCursors"));
853853
newTimer.scheduleAtFixedRate(new Runnable() {
854854
@Override
855855
public void run() {

0 commit comments

Comments
 (0)