SpinningFileLock extends FileLock { @Override public void release() throws IOException { synchronized (lock) { LOCK_TABLE.remove(lock); FileLocks.release(lock); } } protected  SpinningFileLock(FileChannel channel, long position, long size,
            boolean shared); @Override boolean isValid(); @Override void release();  }
@Test public void testOverlappingLockSpinsInSameJvm() throws InterruptedException { FileChannel channel = randomFileChannel(); CountDownLatch latch = new CountDownLatch(2); Thread a = new Thread(() -> { FileLock lock = FileLocks.lock(channel, 0, 10, false); Random.tinySleep(); latch.countDown(); FileLocks.release(lock); }); Thread b = new Thread(() -> { FileLock lock = FileLocks.lock(channel, 3, 8, false); Random.tinySleep(); latch.countDown(); FileLocks.release(lock); }); a.start(); b.start(); latch.await(); Assert.assertTrue(true); }