|
20 | 20 | */
|
21 | 21 | public class SessionPool {
|
22 | 22 |
|
23 |
| - private Logger LOGGER; |
| 23 | + private final Logger LOGGER; |
24 | 24 |
|
25 | 25 | private static final int MAX_AGE_MILLIS = 5000;
|
26 | 26 |
|
27 | 27 | private final LinkedList<PooledSession> sessions = new LinkedList<>();
|
28 |
| - private Connection connection; |
| 28 | + private final Connection connection; |
29 | 29 | private boolean closed = false;
|
30 |
| - private SessionCleaner sessionCleaner = new SessionCleaner(); |
| 30 | + private final SessionCleaner sessionCleaner = new SessionCleaner(); |
31 | 31 |
|
32 | 32 |
|
33 | 33 | public SessionPool(String name, Connection connection) {
|
@@ -58,14 +58,16 @@ public Session getSession() throws JMSException {
|
58 | 58 | /**
|
59 | 59 | * Closes all underlying JMS sessions.
|
60 | 60 | */
|
61 |
| - public synchronized void close() { |
62 |
| - closed = true; |
63 |
| - sessionCleaner.close(); |
64 |
| - sessions.stream().forEach(PooledSession::reallyClose); |
| 61 | + public void close() { |
| 62 | + synchronized (sessions) { |
| 63 | + closed = true; |
| 64 | + sessionCleaner.close(); |
| 65 | + sessions.stream().forEach(PooledSession::reallyClose); |
| 66 | + } |
65 | 67 | }
|
66 | 68 |
|
67 | 69 |
|
68 |
| - public void reclaim(PooledSession session) { |
| 70 | + void reclaim(PooledSession session) { |
69 | 71 | session.markLastUsedTime();
|
70 | 72 | synchronized (sessions){
|
71 | 73 | sessions.add(session);
|
@@ -118,9 +120,11 @@ protected void close(){
|
118 | 120 | cleanupExecutor.shutdown();
|
119 | 121 | }
|
120 | 122 |
|
121 |
| - protected synchronized void start(){ |
122 |
| - cleanupExecutor.scheduleAtFixedRate(command, 5, 5, TimeUnit.SECONDS); |
123 |
| - LOGGER.info("Starting to clean stale sessions..."); |
| 123 | + protected void start() { |
| 124 | + synchronized (sessions) { |
| 125 | + cleanupExecutor.scheduleAtFixedRate(command, 5, 5, TimeUnit.SECONDS); |
| 126 | + LOGGER.info("Starting to clean stale sessions..."); |
| 127 | + } |
124 | 128 | }
|
125 | 129 | }
|
126 | 130 | }
|
0 commit comments