Skip to content

Commit 6d2edfe

Browse files
authored
Interrupt current thread where applicable. (#421)
* Added interruption of current thread on InterruptedException.
1 parent 747a76f commit 6d2edfe

12 files changed

+29
-13
lines changed

quickfixj-core/src/main/java/quickfix/mina/SessionConnector.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ protected void waitForLogout() {
272272
Thread.sleep(100L);
273273
} catch (InterruptedException e) {
274274
log.error(e.getMessage(), e);
275+
Thread.currentThread().interrupt();
275276
}
276277
final long elapsed = System.currentTimeMillis() - start;
277278
Iterator<Session> sessionItr = loggedOnSessions.iterator();
@@ -375,6 +376,7 @@ public void run() {
375376
try {
376377
delegate.await();
377378
} catch (InterruptedException e) {
379+
Thread.currentThread().interrupt();
378380
}
379381
}
380382

@@ -449,9 +451,10 @@ public static void closeManagedSessionsAndDispose(IoService ioService, boolean a
449451
completed = closeFuture.await(1000, TimeUnit.MILLISECONDS);
450452
} catch (InterruptedException ex) {
451453
Thread.currentThread().interrupt();
452-
}
453-
if (!completed) {
454-
logger.warn("Could not close IoSession {}", ioSession);
454+
} finally {
455+
if (!completed) {
456+
logger.warn("Could not close IoSession {}", ioSession);
457+
}
455458
}
456459
}
457460
}

quickfixj-core/src/main/java/quickfix/mina/SingleThreadedEventHandlingStrategy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void onMessage(Session quickfixSession, Message message) {
7676
queueTracker.put(new SessionMessageEvent(quickfixSession, message));
7777
} catch (InterruptedException e) {
7878
isStopped = true;
79-
throw new RuntimeException(e);
79+
Thread.currentThread().interrupt();
8080
}
8181
}
8282

@@ -196,7 +196,8 @@ public void stopHandlingMessages(boolean join) {
196196
try {
197197
messageProcessingThread.join();
198198
} catch (InterruptedException e) {
199-
sessionConnector.log.error("{} interrupted.", MESSAGE_PROCESSOR_THREAD_NAME);
199+
sessionConnector.log.warn("{} interrupted.", MESSAGE_PROCESSOR_THREAD_NAME);
200+
Thread.currentThread().interrupt();
200201
}
201202
}
202203
}

quickfixj-core/src/main/java/quickfix/mina/ThreadPerSessionEventHandlingStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public void enqueue(Message message) {
203203
queueTracker.put(message);
204204
} catch (final InterruptedException e) {
205205
quickfixSession.getLog().onErrorEvent(e.toString());
206+
Thread.currentThread().interrupt();
206207
}
207208
}
208209

@@ -227,6 +228,7 @@ void doRun() {
227228
LogUtil.logThrowable(quickfixSession.getSessionID(),
228229
"Message dispatcher interrupted", e);
229230
stopping = true;
231+
Thread.currentThread().interrupt();
230232
} catch (final Throwable e) {
231233
LogUtil.logThrowable(quickfixSession.getSessionID(),
232234
"Error during message processing", e);

quickfixj-core/src/test/java/quickfix/MultiAcceptorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public void waitForLogon() {
206206
try {
207207
logonLatch.await(20, TimeUnit.SECONDS);
208208
} catch (InterruptedException e) {
209+
Thread.currentThread().interrupt();
209210
fail(e.getMessage());
210211
}
211212
}
@@ -220,6 +221,7 @@ public synchronized void waitForMessages() {
220221
fail("Timed out waiting for message");
221222
}
222223
} catch (InterruptedException e) {
224+
Thread.currentThread().interrupt();
223225
fail(e.getMessage());
224226
}
225227
}

quickfixj-core/src/test/java/quickfix/SessionDisconnectConcurrentlyTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public void waitForLogon() {
134134
try {
135135
logonLatch.await(10, TimeUnit.SECONDS);
136136
} catch (InterruptedException e) {
137+
Thread.currentThread().interrupt();
137138
fail(e.getMessage());
138139
}
139140
}
@@ -148,6 +149,7 @@ public synchronized void waitForMessages() {
148149
fail("Timed out waiting for message");
149150
}
150151
} catch (InterruptedException e) {
152+
Thread.currentThread().interrupt();
151153
fail(e.getMessage());
152154
}
153155
}
@@ -225,7 +227,7 @@ public void run() {
225227
try {
226228
Thread.sleep(12000);
227229
} catch (InterruptedException e) {
228-
e.printStackTrace();
230+
Thread.currentThread().interrupt();
229231
}
230232
threadIds = bean.findDeadlockedThreads();
231233
}

quickfixj-core/src/test/java/quickfix/mina/LostLogoutTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void fromApp(Message message, SessionID sessionId) throws FieldNotFound,
144144
try {
145145
Thread.sleep(1000);
146146
} catch (InterruptedException e) {
147-
e.printStackTrace();
147+
Thread.currentThread().interrupt();
148148
}
149149
System.out.println("Server: message processing end");
150150
}

quickfixj-core/src/test/java/quickfix/mina/LostLogoutThreadedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void fromApp(Message message, SessionID sessionId) throws FieldNotFound,
144144
try {
145145
Thread.sleep(1000);
146146
} catch (InterruptedException e) {
147-
e.printStackTrace();
147+
Thread.currentThread().interrupt();
148148
}
149149
System.out.println("Server: message processing end");
150150
}

quickfixj-core/src/test/java/quickfix/mina/SingleThreadedEventHandlingStrategyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void cleanup() {
6868
try {
6969
Thread.sleep(500);
7070
} catch (InterruptedException ex) {
71-
// ignored
71+
Thread.currentThread().interrupt();
7272
}
7373
}
7474
}
@@ -373,7 +373,7 @@ private static void assertQFJMessageProcessorThreads(int expected) {
373373
try {
374374
Thread.sleep(100);
375375
} catch (InterruptedException ex) {
376-
// ignored
376+
Thread.currentThread().interrupt();
377377
}
378378
dumpAllThreads = bean.dumpAllThreads(false, false);
379379
qfjMPThreads = getMessageProcessorThreads(dumpAllThreads);

quickfixj-core/src/test/java/quickfix/mina/ssl/SSLAndNonSSLTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public void run() {
214214
shutdownLatch.await();
215215
} catch (InterruptedException e1) {
216216
try {
217+
Thread.currentThread().interrupt();
217218
acceptor.stop(true);
218219
} catch (RuntimeException e) {
219220
e.printStackTrace();

quickfixj-core/src/test/java/quickfix/mina/ssl/SSLCertificateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void cleanup() {
6565
try {
6666
Thread.sleep(500);
6767
} catch (InterruptedException ex) {
68+
Thread.currentThread().interrupt();
6869
java.util.logging.Logger.getLogger(SSLCertificateTest.class.getName()).log(Level.SEVERE, null, ex);
6970
}
7071
}

0 commit comments

Comments
 (0)