### Question:
MulSemaphore { public DALPermitsSet acquire(BitSet ids) throws InterruptedException { final ReentrantLock takeLock = this.takeLock; DALPermitsSet re = tryAcquire(ids); if (re.getMisIds().isEmpty()) { return re; } while (re.getIds().isEmpty()) { takeLock.lockInterruptibly(); try { while (!hasAvailablePermits(re.getMisIds())) { notEmpty.await(); signalNotEmpty(); } } finally { takeLock.unlock(); } DALPermitsSet tmp = re; re = tryAcquire(re.getMisIds()); tmp.release(); } return re; } MulSemaphore(int maxSemaphoreNumber); synchronized void unregister(int id); int availablePermits(int id); void putPermits(int id, int permits, int decimalPermits); DALPermitsSet tryAcquire(BitSet ids); DALPermitsSet overdrawAcquire(BitSet ids); DALPermitsSet tryAcquire(long time, TimeUnit timeUnit, BitSet ids); DALPermitsSet acquire(BitSet ids); DALPermitsSet newDALPermitsSet(); @Override String toString(); String getInfo(BitSet ids);  }### Answer:
@Test public void acquire() throws InterruptedException { final MulSemaphore ms = new MulSemaphore(0x20); BitSet bitset = new BitSet(0x20); bitset.set(0, 2); ms.putPermits(0, 10, 0); ms.putPermits(1, 10, 0); Assert.assertEquals(ms.availablePermits(0), 10); final List<DALPermitsSet> dalPermits = new ArrayList<>(); IntStream.range(0, 10).forEach(i -> { try { dalPermits.add(ms.acquire(bitset)); } catch (Exception e) { logger.error("Exception in MulSemaphoreTest.acquire():", e); } }); Assert.assertEquals(dalPermits.size(), 10); Thread t = new Thread(() -> { try { Thread.sleep(200); dalPermits.forEach(dalp -> { dalp.release(); }); } catch (Exception e) { logger.error("Exception in MulSemaphoreTest.acquire():", e); } }); long start = System.currentTimeMillis(); t.start(); ms.acquire(bitset); long dur = System.currentTimeMillis() - start; Assert.assertTrue(dur >= 200); t.join(); Assert.assertEquals(ms.availablePermits(0), 9); }