1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  package ch.qos.logback.classic;
11  
12  import java.io.ByteArrayInputStream;
13  
14  import org.junit.After;
15  import org.junit.Before;
16  import org.junit.Test;
17  
18  import ch.qos.logback.classic.joran.JoranConfigurator;
19  import ch.qos.logback.core.joran.spi.JoranException;
20  
21  public class LoggerContextDeadlockTest {
22  
23    LoggerContext loggerContext = new LoggerContext();
24    JoranConfigurator jc = new JoranConfigurator();
25    GetLoggerThread getLoggerThread = new GetLoggerThread(loggerContext);
26  
27    @Before
28    public void setUp() throws Exception {
29      jc.setContext(loggerContext);
30    }
31  
32    @After
33    public void tearDown() throws Exception {
34    }
35  
36    @Test(timeout=20000)
37    public void testLBCLASSIC_81() throws JoranException {
38  
39  
40      getLoggerThread.start();
41      for (int i = 0; i < 500; i++) {
42        ByteArrayInputStream baos = new ByteArrayInputStream(new String(
43        "<configuration><root level=\"DEBUG\"/></configuration>").getBytes());
44        jc.doConfigure(baos);
45      }
46    }
47  
48    class GetLoggerThread extends Thread {
49  
50      final LoggerContext loggerContext;
51      GetLoggerThread(LoggerContext loggerContext) {
52        this.loggerContext = loggerContext;
53      }
54      @Override
55      public void run() {
56        for (int i = 0; i < 10000; i++) {
57          if(i % 100 == 0) {
58            try {
59              Thread.sleep(1);
60            } catch (InterruptedException e) {
61            }
62          }
63          loggerContext.getLogger("a" + i);
64        }
65      }
66    }
67  
68  }