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;
15  
16  import java.io.ByteArrayInputStream;
17  
18  import org.junit.After;
19  import org.junit.Before;
20  import org.junit.Test;
21  
22  import ch.qos.logback.classic.joran.JoranConfigurator;
23  import ch.qos.logback.core.joran.spi.JoranException;
24  
25  public class LoggerContextDeadlockTest {
26  
27      LoggerContext loggerContext = new LoggerContext();
28      JoranConfigurator jc = new JoranConfigurator();
29      GetLoggerThread getLoggerThread = new GetLoggerThread(loggerContext);
30  
31      @Before
32      public void setUp() throws Exception {
33          jc.setContext(loggerContext);
34      }
35  
36      @After
37      public void tearDown() throws Exception {
38      }
39  
40      @Test(timeout = 20000)
41      public void testLBCLASSIC_81() throws JoranException {
42  
43          getLoggerThread.start();
44          for (int i = 0; i < 500; i++) {
45              ByteArrayInputStream baos = new ByteArrayInputStream("<configuration><root level=\"DEBUG\"/></configuration>".getBytes());
46              jc.doConfigure(baos);
47          }
48      }
49  
50      class GetLoggerThread extends Thread {
51  
52          final LoggerContext loggerContext;
53  
54          GetLoggerThread(LoggerContext loggerContext) {
55              this.loggerContext = loggerContext;
56          }
57  
58          @Override
59          public void run() {
60              for (int i = 0; i < 10000; i++) {
61                  if (i % 100 == 0) {
62                      try {
63                          Thread.sleep(1);
64                      } catch (InterruptedException e) {
65                      }
66                  }
67                  loggerContext.getLogger("a" + i);
68              }
69          }
70      }
71  
72  }