< prev index next >

test/java/util/logging/LogManagerAppContextDeadlock.java

Print this page




 124         public void run() throws Exception {
 125             System.out.println("Running test case: " + name());
 126             Configure.setUp(this);
 127             test(this);
 128         }
 129     }
 130 
 131     public static void test(TestCase test) throws Exception {
 132         Thread t1 = new Thread() {
 133             @Override
 134             public void run() {
 135                 sem3.release();
 136                 System.out.println("FakeAppContext.getAppContext()");
 137                 FakeAppContext.getAppContext();
 138                 System.out.println("Done: FakeAppContext.getAppContext()");
 139             }
 140         };
 141         t1.setDaemon(true);
 142         t1.start();
 143         Thread t2 = new Thread() {

 144             public void run() {
 145                 sem3.release();
 146                 try {
 147                     // Wait until Thread1 is in FakeAppContext constructor
 148                     sem2.acquire();
 149                     System.out.println("Sem2 acquired: Thread #1 will be waiting to acquire Sem");
 150                 } catch (InterruptedException ie) {
 151                     Thread.interrupted();
 152                 }
 153                 System.out.println("Logger.getLogger(name).info(name)");
 154                 Logger.getLogger(test.name());//.info(name);



 155                 System.out.println("Done: Logger.getLogger(name).info(name)");
 156             }
 157         };
 158         t2.setDaemon(true);
 159         t2.start();
 160         System.out.println("Should exit now...");
 161         Thread detector = new DeadlockDetector();
 162         detector.start();
 163 
 164         // Wait for the 3 threads to start
 165         sem3.acquire();
 166 
 167         // Now wait for t1 & t2 to finish, or for a deadlock to be detected.
 168         while (goOn && (t1.isAlive() || t2.isAlive())) {
 169             if (t2.isAlive()) t2.join(1000);
 170             if (test == TestCase.UNSECURE && System.getSecurityManager() == null) {
 171                 // if there's no security manager, AppContext.getAppContext() is
 172                 // not called -  so Thread t2 will not end up calling
 173                 // sem.release(). In that case we must release the semaphore here
 174                 // so that t1 can proceed.




 124         public void run() throws Exception {
 125             System.out.println("Running test case: " + name());
 126             Configure.setUp(this);
 127             test(this);
 128         }
 129     }
 130 
 131     public static void test(TestCase test) throws Exception {
 132         Thread t1 = new Thread() {
 133             @Override
 134             public void run() {
 135                 sem3.release();
 136                 System.out.println("FakeAppContext.getAppContext()");
 137                 FakeAppContext.getAppContext();
 138                 System.out.println("Done: FakeAppContext.getAppContext()");
 139             }
 140         };
 141         t1.setDaemon(true);
 142         t1.start();
 143         Thread t2 = new Thread() {
 144             public Object logger;
 145             public void run() {
 146                 sem3.release();
 147                 try {
 148                     // Wait until Thread1 is in FakeAppContext constructor
 149                     sem2.acquire();
 150                     System.out.println("Sem2 acquired: Thread #1 will be waiting to acquire Sem");
 151                 } catch (InterruptedException ie) {
 152                     Thread.interrupted();
 153                 }
 154                 System.out.println("Logger.getLogger(name).info(name)");
 155                 // stick the logger in an instance variable to prevent it
 156                 // from being garbage collected before the main thread
 157                 // calls LogManager.getLogger() below.
 158                 logger = Logger.getLogger(test.name());//.info(name);
 159                 System.out.println("Done: Logger.getLogger(name).info(name)");
 160             }
 161         };
 162         t2.setDaemon(true);
 163         t2.start();
 164         System.out.println("Should exit now...");
 165         Thread detector = new DeadlockDetector();
 166         detector.start();
 167 
 168         // Wait for the 3 threads to start
 169         sem3.acquire();
 170 
 171         // Now wait for t1 & t2 to finish, or for a deadlock to be detected.
 172         while (goOn && (t1.isAlive() || t2.isAlive())) {
 173             if (t2.isAlive()) t2.join(1000);
 174             if (test == TestCase.UNSECURE && System.getSecurityManager() == null) {
 175                 // if there's no security manager, AppContext.getAppContext() is
 176                 // not called -  so Thread t2 will not end up calling
 177                 // sem.release(). In that case we must release the semaphore here
 178                 // so that t1 can proceed.


< prev index next >