Skip to content

Commit

Permalink
[LOGBACK-1754] fixed use of CountDownLatch
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Habermehl <13348120+schabe77@users.noreply.github.com>
  • Loading branch information
schabe77 authored and ceki committed Jul 23, 2023
1 parent be5afc2 commit 5ceb7c5
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ public void beforeEach() {
// see https://jira.qos.ch/browse/LOGBACK-1754
@Test
public void assertNoOverlappingFileLockException () throws IOException {
CountDownLatch latch = new CountDownLatch(THREAD_COUNT);
CountDownLatch latch = new CountDownLatch(1);
List<Thread> threads = new ArrayList<>(THREAD_COUNT);
for (int i = 0; i < THREAD_COUNT; i++) {
LoggerThread thread = new LoggerThread(latch, "message from thread " + i);
thread.start();
threads.add(thread);
}
latch.countDown();
int i = 0;
for (Thread thread : threads) {
try {
Expand Down Expand Up @@ -106,13 +107,17 @@ class LoggerThread extends Thread {

@Override
public void run() {
latch.countDown();
for (int i = 0; i < LOOP_COUNT; i++) {
if ((i & 0x08) == 0) {
// yield to spice it up
Thread.yield();
try {
latch.await();
for (int i = 0; i < LOOP_COUNT; i++) {
if ((i & 0x08) == 0) {
// yield to spice it up
Thread.yield();
}
PrudentModeTest.this.fa.doAppend(message + " i=" + i);
}
PrudentModeTest.this.fa.doAppend(message + " i=" + i);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}

Expand Down

0 comments on commit 5ceb7c5

Please sign in to comment.