@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null; } } } }
/** * Runs an {@link V8Runnable} on the V8 thread. * * <b>Note: </b> This method executes synchronously, not asynchronously; * it will not return until the passed {@link V8Runnable} is done * executing. The method is also synchronized, so it will block until it * gets a chance to run. * * @param runnable {@link V8Runnable} to run. */ public synchronized void run(final V8Runnable runnable) { try { v8.getLocker().acquire(); runnable.run(v8); } finally { if ((v8 != null) && (v8.getLocker() != null) && v8.getLocker().hasLock()) { v8.getLocker().release(); } } }
} finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null;
@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null; } } } }
@Override public void run(final V8 runtime) { assertTrue(runtime.getLocker().hasLock()); } });
@Test public void testHasLock() { V8Locker v8Locker = new V8Locker(v8); assertTrue(v8Locker.hasLock()); }
/** * Runs an {@link V8Runnable} on the V8 thread. * * <b>Note: </b> This method executes synchronously, not asynchronously; * it will not return until the passed {@link V8Runnable} is done * executing. The method is also synchronized, so it will block until it * gets a chance to run. * * @param runnable {@link V8Runnable} to run. */ public synchronized void run(final V8Runnable runnable) { try { v8.getLocker().acquire(); runnable.run(v8); } finally { if ((v8 != null) && (v8.getLocker() != null) && v8.getLocker().hasLock()) { v8.getLocker().release(); } } }
} finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null;
@Test public void testDoesNotHasLock() { V8Locker v8Locker = new V8Locker(v8); v8Locker.release(); assertFalse(v8Locker.hasLock()); }
@Test public void testLockNotAquiredAfterCreation() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }
@Test public void testLockNotAcquiredAfterExecution() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); concurrentV8.run(new V8Runnable() { @Override public void run(final V8 runtime) { runtime.executeScript("foo = 7;"); } }); assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }
@Test public void testLockNotAquiredAfterException() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); try { concurrentV8.run(new V8Runnable() { @Override public void run(final V8 runtime) { runtime.executeScript("throw 'my exception';"); } }); } catch (Exception e) { // do nothing } assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }
@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.release(); runtime = null; } } } }
@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.release(); runtime = null; } } } }
} finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.release(); runtime = null;
} finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.release(); runtime = null;