/* * see bug 121737 * To ensure that we do not enter a deadly embrace between classloader cycles * we attempt to obtain a global lock before do normal osgi delegation. * This approach ensures that only one thread has a classloader locked at a time */ private static void lock(Object loader) { Thread currentThread = Thread.currentThread(); boolean interrupted = false; synchronized (loader) { if (tryLock(currentThread, loader)) return; // this thread has the lock do { try { // we wait on the loader object here to release its lock incase we have it. // we do not way to wait while holding this lock because that will cause deadlock loader.wait(); } catch (InterruptedException e) { interrupted = true; // we still want to try again } } while (!tryLock(currentThread)); } if (interrupted) currentThread.interrupt(); }