com.eclipsesource.v8.V8.getLocker()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中com.eclipsesource.v8.V8.getLocker()方法的一些代码示例,展示了V8.getLocker()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。V8.getLocker()方法的具体详情如下:
包路径:com.eclipsesource.v8.V8
类名称:V8
方法名:getLocker

V8.getLocker介绍

[英]Returns the locker associated with this runtime. The locker allows threads to give up control of the runtime and other threads to acquire control.
[中]返回与此运行时关联的储物柜。locker允许线程放弃对运行时的控制,并允许其他线程获得控制。

代码示例

代码示例来源:origin: eclipsesource/J2V8

/**
 * Removes a handler from the list of breakpoint handlers.
 * If the handler is not present in the list, the list is unchanged.
 *
 * @param handler The handler to remove.
 */
public void removeBreakHandler(final BreakHandler handler) {
  runtime.getLocker().checkThread();
  breakHandlers.remove(handler);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Adds a handler to be notified when a breakpoint is hit.
 *
 * @param handler The handler to notify.
 */
public void addBreakHandler(final BreakHandler handler) {
  runtime.getLocker().checkThread();
  breakHandlers.add(handler);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * 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();
    }
  }
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Create a new ConcurrentV8. A ConcurrentV8 allows multiple
 * threads to work with the same V8 engine by releasing
 * the locks between calls.
 */
public ConcurrentV8() {
  v8 = V8.createV8Runtime();
  v8.getLocker().release();
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Persist an object that is currently being managed by this Manager.
 *
 * Objects that are being managed by a MemoryManager will be released
 * once the MemoryManager is released. If an object is persisted, it will
 * be remove from the MemoryManager's control and therefore will not
 * be released.
 *
 * @param object The object to persist
 */
public void persist(final V8Value object) {
  v8.getLocker().checkThread();
  checkReleased();
  references.remove(object);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Releases this Memory Manager and all V8Objects that were created while
 * this memory manager was active.
 */
public void release() {
  v8.getLocker().checkThread();
  if (released) {
    return;
  }
  releasing = true;
  try {
    for (V8Value reference : references) {
      reference.close();
    }
    v8.removeReferenceHandler(memoryManagerReferenceHandler);
    references.clear();
  } finally {
    releasing = false;
  }
  released = true;
}

代码示例来源:origin: eclipsesource/J2V8

@Override
public void run() {
  runtime = V8.createV8Runtime();
  try {
    target.run(runtime);
  } finally {
    synchronized (this) {
      if (runtime.getLocker().hasLock()) {
        runtime.close();
        runtime = null;
      }
    }
  }
}

代码示例来源:origin: eclipsesource/J2V8

} finally {
  synchronized (this) {
    if (runtime.getLocker().hasLock()) {
      runtime.close();
      runtime = null;

代码示例来源:origin: eclipsesource/J2V8

/**
 * Adds a handler to be notified when a breakpoint is hit.
 *
 * @param handler The handler to notify.
 */
public void addBreakHandler(final BreakHandler handler) {
  runtime.getLocker().checkThread();
  breakHandlers.add(handler);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Removes a handler from the list of breakpoint handlers.
 * If the handler is not present in the list, the list is unchanged.
 *
 * @param handler The handler to remove.
 */
public void removeBreakHandler(final BreakHandler handler) {
  runtime.getLocker().checkThread();
  breakHandlers.remove(handler);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Persist an object that is currently being managed by this Manager.
 *
 * Objects that are being managed by a MemoryManager will be released
 * once the MemoryManager is released. If an object is persisted, it will
 * be remove from the MemoryManager's control and therefore will not
 * be released.
 *
 * @param object The object to persist
 */
public void persist(final V8Value object) {
  v8.getLocker().checkThread();
  checkReleased();
  references.remove(object);
}

代码示例来源:origin: eclipsesource/J2V8

/**
 * Create a new ConcurrentV8. A ConcurrentV8 allows multiple
 * threads to work with the same V8 engine by releasing
 * the locks between calls.
 */
public ConcurrentV8() {
  v8 = V8.createV8Runtime();
  v8.getLocker().release();
}

代码示例来源:origin: eclipsesource/J2V8

@Override
  public Object invoke(final V8Object receiver, final V8Array parameters) {
    v8.getLocker().release();
    v8.getLocker().acquire();
    return null;
  }
}, "foo");

代码示例来源:origin: eclipsesource/J2V8

@Override
  public void run() {
    v8.getLocker().acquire();
    v8.getLocker().release();
  }
});

代码示例来源:origin: eclipsesource/J2V8

@Override
  public void run() {
    v8.getLocker().acquire();
    v8.add("foo", "baz");
    v8.getLocker().release();
  }
});

代码示例来源:origin: eclipsesource/J2V8

@Override
public void run() {
  runtime = V8.createV8Runtime();
  try {
    target.run(runtime);
  } finally {
    synchronized (this) {
      if (runtime.getLocker().hasLock()) {
        runtime.close();
        runtime = null;
      }
    }
  }
}

代码示例来源:origin: eclipsesource/J2V8

@Override
  public Object invoke(final V8Object receiver, final V8Array parameters) {
    v8TempRuntime = V8.createV8Runtime();
    v8TempRuntime.getLocker().release();
    throw new RuntimeException();
  }
}, "foo");

代码示例来源:origin: eclipsesource/J2V8

@Override
  public void run(final V8 runtime) {
    assertTrue(runtime.getLocker().hasLock());
  }
});

代码示例来源:origin: eclipsesource/J2V8

@Test
public void testLockNotAquiredAfterCreation() {
  ConcurrentV8 concurrentV8 = new ConcurrentV8();
  assertFalse(concurrentV8.getV8().getLocker().hasLock());
  concurrentV8.release();
}

代码示例来源:origin: eclipsesource/J2V8

@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();
}

相关文章

V8类方法