Skip to content

Commit 0122af3

Browse files
Get rid of our custom ThreadFactory interface, solely rely on j.u.c.ThreadFactory
1 parent c01fff5 commit 0122af3

File tree

8 files changed

+23
-55
lines changed

8 files changed

+23
-55
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
import java.net.URI;
2626
import java.net.URISyntaxException;
2727
import java.net.URLDecoder;
28+
import java.util.concurrent.Executors;
29+
import java.util.concurrent.ThreadFactory;
2830

2931
import javax.net.SocketFactory;
3032
import javax.net.ssl.SSLSocketFactory;
3133
import javax.net.ssl.SSLContext;
3234
import javax.net.ssl.TrustManager;
3335

3436
import com.rabbitmq.client.impl.AMQConnection;
35-
import com.rabbitmq.client.impl.DefaultThreadFactory;
3637
import com.rabbitmq.client.impl.ConnectionParams;
3738
import com.rabbitmq.client.impl.DefaultExceptionHandler;
3839
import com.rabbitmq.client.impl.FrameHandler;
@@ -91,7 +92,7 @@ public class ConnectionFactory implements Cloneable {
9192
private SocketFactory factory = SocketFactory.getDefault();
9293
private SaslConfig saslConfig = DefaultSaslConfig.PLAIN;
9394
private ExecutorService sharedExecutor;
94-
private ThreadFactory threadFactory = new DefaultThreadFactory();
95+
private ThreadFactory threadFactory = Executors.defaultThreadFactory();
9596
private SocketConfigurator socketConf = new DefaultSocketConfigurator();
9697
private ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
9798

@@ -432,17 +433,15 @@ public void setSharedExecutor(ExecutorService executor) {
432433

433434
/**
434435
* Retrieve the thread factory used to instantiate new threads.
435-
* @see com.rabbitmq.client.ThreadFactory
436-
* @see com.rabbitmq.client.impl.DefaultThreadFactory
436+
* @see ThreadFactory
437437
*/
438438
public ThreadFactory getThreadFactory() {
439439
return threadFactory;
440440
}
441441

442442
/**
443443
* Set the thread factory used to instantiate new threads.
444-
* @see com.rabbitmq.client.ThreadFactory
445-
* @see com.rabbitmq.client.impl.DefaultThreadFactory
444+
* @see ThreadFactory
446445
*/
447446
public void setThreadFactory(ThreadFactory threadFactory) {
448447
this.threadFactory = threadFactory;

src/com/rabbitmq/client/ThreadFactory.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.util.Map;
2828
import java.util.concurrent.CopyOnWriteArrayList;
2929
import java.util.concurrent.ExecutorService;
30+
import java.util.concurrent.Executors;
31+
import java.util.concurrent.ThreadFactory;
3032
import java.util.concurrent.TimeoutException;
3133

3234
import com.rabbitmq.client.AMQP;
@@ -46,7 +48,6 @@
4648
import com.rabbitmq.client.SaslConfig;
4749
import com.rabbitmq.client.SaslMechanism;
4850
import com.rabbitmq.client.ShutdownSignalException;
49-
import com.rabbitmq.client.ThreadFactory;
5051
import com.rabbitmq.client.impl.AMQChannel.BlockingRpcContinuation;
5152
import com.rabbitmq.utility.BlockingCell;
5253

@@ -66,7 +67,7 @@ public class AMQConnection extends ShutdownNotifierComponent implements Connecti
6667
public static final int HANDSHAKE_TIMEOUT = 10000;
6768
private final ExecutorService executor;
6869
private Thread mainLoopThread;
69-
private ThreadFactory threadFactory = new DefaultThreadFactory();
70+
private ThreadFactory threadFactory = Executors.defaultThreadFactory();
7071

7172
/**
7273
* Retrieve a copy of the default table of client properties that
@@ -280,7 +281,11 @@ public void start()
280281

281282
// start the main loop going
282283
MainLoop loop = new MainLoop();
283-
mainLoopThread = threadFactory.newThread(loop, "AMQP Connection " + getHostAddress() + ":" + getPort());
284+
final String threadName = "AMQP Connection " + getHostAddress() + ":" + getPort();
285+
mainLoopThread = threadFactory.newThread(loop);
286+
if(Environment.isAllowedToModifyThreads()) {
287+
mainLoopThread.setName(threadName);
288+
}
284289
mainLoopThread.start();
285290
// after this point clear-up of MainLoop is triggered by closing the frameHandler.
286291

src/com/rabbitmq/client/impl/ChannelManager.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424
import java.util.concurrent.CountDownLatch;
25+
import java.util.concurrent.Executors;
26+
import java.util.concurrent.ThreadFactory;
2527
import java.util.concurrent.TimeUnit;
2628

2729
import com.rabbitmq.client.ShutdownSignalException;
28-
import com.rabbitmq.client.ThreadFactory;
2930
import com.rabbitmq.utility.IntAllocator;
3031

3132
/**
@@ -53,7 +54,7 @@ public int getChannelMax(){
5354
}
5455

5556
public ChannelManager(ConsumerWorkService workService, int channelMax) {
56-
this(workService, channelMax, new DefaultThreadFactory());
57+
this(workService, channelMax, Executors.defaultThreadFactory());
5758
}
5859

5960
public ChannelManager(ConsumerWorkService workService, int channelMax, ThreadFactory threadFactory) {
@@ -112,8 +113,9 @@ public void run() {
112113
ssWorkService.shutdown();
113114
}
114115
};
115-
Thread shutdownThread = threadFactory.newThread(target, "ConsumerWorkService shutdown monitor");
116+
Thread shutdownThread = threadFactory.newThread(target);
116117
if(Environment.isAllowedToModifyThreads()) {
118+
shutdownThread.setName("ConsumerWorkService shutdown monitor");
117119
shutdownThread.setDaemon(true);
118120
}
119121
shutdownThread.start();

src/com/rabbitmq/client/impl/ConnectionParams.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import com.rabbitmq.client.ExceptionHandler;
44
import com.rabbitmq.client.SaslConfig;
5-
import com.rabbitmq.client.ThreadFactory;
65

76
import java.util.Map;
87
import java.util.concurrent.ExecutorService;
8+
import java.util.concurrent.ThreadFactory;
99

1010
public class ConnectionParams {
1111
private final String username;
@@ -21,7 +21,7 @@ public class ConnectionParams {
2121
private final boolean topologyRecovery;
2222

2323
private ExceptionHandler exceptionHandler;
24-
private ThreadFactory threadFactory;
24+
private ThreadFactory threadFactory;
2525

2626
/**
2727
* @param username name used to establish connection

src/com/rabbitmq/client/impl/DefaultThreadFactory.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/com/rabbitmq/client/impl/recovery/RecoveryAwareAMQConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.rabbitmq.client.impl.recovery;
22

3-
import com.rabbitmq.client.ThreadFactory;
43
import com.rabbitmq.client.impl.AMQConnection;
54
import com.rabbitmq.client.impl.ConnectionParams;
65
import com.rabbitmq.client.impl.FrameHandler;
76

7+
import java.util.concurrent.ThreadFactory;
8+
89
/**
910
* {@link com.rabbitmq.client.impl.AMQConnection} modification that uses {@link com.rabbitmq.client.impl.recovery.RecoveryAwareChannelN}
1011
* @since 3.3.0

test/src/com/rabbitmq/client/test/server/ChannelLimitNegotiation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.rabbitmq.client.ShutdownSignalException;
88
import com.rabbitmq.client.impl.AMQConnection;
99
import com.rabbitmq.client.impl.ChannelN;
10-
import com.rabbitmq.client.impl.DefaultThreadFactory;
1110
import com.rabbitmq.client.impl.SocketFrameHandler;
1211
import com.rabbitmq.client.impl.ConsumerWorkService;
1312
import com.rabbitmq.client.test.BrokerTestCase;
@@ -81,7 +80,7 @@ public void testOpeningTooManyChannels() throws Exception {
8180

8281
// Construct a channel directly
8382
final ChannelN ch = new ChannelN((AMQConnection) conn, n + 1,
84-
new ConsumerWorkService(Executors.newSingleThreadExecutor(), new DefaultThreadFactory()));
83+
new ConsumerWorkService(Executors.newSingleThreadExecutor(), Executors.defaultThreadFactory()));
8584
conn.addShutdownListener(new ShutdownListener() {
8685
public void shutdownCompleted(ShutdownSignalException cause) {
8786
// make sure channel.open continuation is released

0 commit comments

Comments
 (0)