Skip to content

Commit 950cbdf

Browse files
schabe77ceki
authored andcommitted
[LOGBACK-1754] fixed use of CountDownLatch
Signed-off-by: Christian Habermehl <[email protected]>
1 parent 4b4b68c commit 950cbdf

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

logback-core/src/test/java/ch/qos/logback/core/util/PrudentModeTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ public void beforeEach() {
6767
// see https://jira.qos.ch/browse/LOGBACK-1754
6868
@Test
6969
public void assertNoOverlappingFileLockException () throws IOException {
70-
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
70+
CountDownLatch latch = new CountDownLatch(1);
7171
List<Thread> threads = new ArrayList<>(THREAD_COUNT);
7272
for (int i = 0; i < THREAD_COUNT; i++) {
7373
LoggerThread thread = new LoggerThread(latch, "message from thread " + i);
7474
thread.start();
7575
threads.add(thread);
7676
}
77+
latch.countDown();
7778
int i = 0;
7879
for (Thread thread : threads) {
7980
try {
@@ -106,13 +107,17 @@ class LoggerThread extends Thread {
106107

107108
@Override
108109
public void run() {
109-
latch.countDown();
110-
for (int i = 0; i < LOOP_COUNT; i++) {
111-
if ((i & 0x08) == 0) {
112-
// yield to spice it up
113-
Thread.yield();
110+
try {
111+
latch.await();
112+
for (int i = 0; i < LOOP_COUNT; i++) {
113+
if ((i & 0x08) == 0) {
114+
// yield to spice it up
115+
Thread.yield();
116+
}
117+
PrudentModeTest.this.fa.doAppend(message + " i=" + i);
114118
}
115-
PrudentModeTest.this.fa.doAppend(message + " i=" + i);
119+
} catch (InterruptedException ex) {
120+
Thread.currentThread().interrupt();
116121
}
117122
}
118123

0 commit comments

Comments
 (0)