View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.issue.lbclassic135.lbclassic139;
15  
16  import org.junit.jupiter.api.BeforeEach;
17  
18  import ch.qos.logback.classic.BasicConfigurator;
19  import ch.qos.logback.classic.LoggerContext;
20  import org.junit.jupiter.api.Test;
21  
22  public class LB139_DeadlockTest {
23  
24      LoggerContext loggerContext = new LoggerContext();
25  
26      @BeforeEach
27      public void setUp() {
28          loggerContext.setName("LB139");
29          BasicConfigurator bc = new BasicConfigurator();
30          bc.setContext(loggerContext);
31          bc.configure(loggerContext);
32      }
33  
34      @Test
35      // (timeout=3000)
36      public void test() throws Exception {
37          Worker worker = new Worker(loggerContext);
38          Accessor accessor = new Accessor(worker, loggerContext);
39  
40          Thread workerThread = new Thread(worker, "WorkerThread");
41          Thread accessorThread = new Thread(accessor, "AccessorThread");
42  
43          workerThread.start();
44          accessorThread.start();
45  
46          int sleep = Worker.SLEEP_DUIRATION * 10;
47  
48          System.out.println("Will sleep for " + sleep + " millis");
49          Thread.sleep(sleep);
50          System.out.println("Done sleeping (" + sleep + " millis)");
51          worker.setDone(true);
52          accessor.setDone(true);
53  
54          workerThread.join();
55          accessorThread.join();
56      }
57  }