java.util.concurrent.ForkJoinPool.managedBlock()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(190)

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

ForkJoinPool.managedBlock介绍

[英]Blocks in accord with the given blocker. If the current thread is a ForkJoinWorkerThread, this method possibly arranges for a spare thread to be activated if necessary to ensure sufficient parallelism while the current thread is blocked.

If the caller is not a ForkJoinTask, this method is behaviorally equivalent to

while (!blocker.isReleasable())

If the caller is a ForkJoinTask, then the pool may first be expanded to ensure parallelism, and later adjusted.
[中]与给定拦截器一致的拦截器。如果当前线程是ForkJoinWorkerThread,此方法可能会在必要时安排激活备用线程,以确保在当前线程被阻塞时具有足够的并行性。
如果调用方不是ForkJoinTask,则此方法在行为上等同于

while (!blocker.isReleasable())

如果调用方是ForkJoinTask,则可以首先扩展池以确保并行性,然后进行调整。

代码示例

代码示例来源:origin: vavr-io/vavr

ForkJoinPool.managedBlock(new ForkJoinPool.ManagedBlocker() {

代码示例来源:origin: robovm/robovm

ForkJoinPool.managedBlock(node);
} catch (InterruptedException ie) {
  node.wasInterrupted = true;

代码示例来源:origin: lenskit/lenskit

/**
 * Acquire a semaphore, coordinating with the fork-join pool if one is running.
 * @param s The semaphore to acquire.
 */
public static void acquireSemaphore(Semaphore s) throws InterruptedException {
  ForkJoinPool.managedBlock(new SemaphoreBlocker(s));
}

代码示例来源:origin: lenskit/lenskit

/**
 * Enter a monitor, releasing coordinating with the fork-join pool.
 * @param m The monitor to enter.
 */
public static void enterMonitor(Monitor m) throws InterruptedException {
  ForkJoinPool.managedBlock(new MonitorBlocker(m));
}

代码示例来源:origin: kabutz/javaspecialists

private static void managedBlock(
    AlwaysBlockingManagedBlocker blocker)
    throws InterruptedException {
  ForkJoinPool.managedBlock(blocker);
}

代码示例来源:origin: Syncleus/aparapi

public void awaitOnLocalBarrier() {
  boolean completed = false;
  final IKernelBarrier barrier = localBarrier.get();
  while (!completed && barrier != null) {
    try {
      ForkJoinPool.managedBlock(barrier); //ManagedBlocker already has to be reentrant
      completed = true;
    } catch (InterruptedException ex) {
      //Empty on purpose, either barrier is disabled on InterruptedException or lock will have to complete
    }
  }
}

代码示例来源:origin: groupon/monsoon

@Override
public void run() {
  try {
    ForkJoinPool.managedBlock(this);
  } catch (InterruptedException ex) {
    LOG.log(Level.WARNING, "interrupted wait", ex);
  }
}

代码示例来源:origin: org.junit.platform/junit-platform-engine

@Override
public ResourceLock acquire() throws InterruptedException {
  ForkJoinPool.managedBlock(new SingleLockManagedBlocker());
  return this;
}

代码示例来源:origin: org.junit.platform/junit-platform-engine

@Override
public ResourceLock acquire() throws InterruptedException {
  ForkJoinPool.managedBlock(new CompositeLockManagedBlocker());
  return this;
}

代码示例来源:origin: org.lenskit/lenskit-core

/**
 * Enter a monitor, releasing coordinating with the fork-join pool.
 * @param m The monitor to enter.
 */
public static void enterMonitor(Monitor m) throws InterruptedException {
  ForkJoinPool.managedBlock(new MonitorBlocker(m));
}

代码示例来源:origin: org.lenskit/lenskit-core

/**
 * Acquire a semaphore, coordinating with the fork-join pool if one is running.
 * @param s The semaphore to acquire.
 */
public static void acquireSemaphore(Semaphore s) throws InterruptedException {
  ForkJoinPool.managedBlock(new SemaphoreBlocker(s));
}

代码示例来源:origin: PreferredAI/venom

@Override
public final void executeBlockingIO(final @NotNull Runnable task) {
 if (task == null) {
  throw new NullPointerException();
 }
 final ManagedBlockerTask managedBlockerTask = new ManagedBlockerTask(task);
 try {
  ForkJoinPool.managedBlock(managedBlockerTask);
 } catch (InterruptedException e) {
  Thread.currentThread().interrupt();
  throw new AssertionError("Exception of unknown cause. Please verify codebase.", e);
 }
}

代码示例来源:origin: kabutz/javaspecialists

public void lockInterruptibly() throws InterruptedException {
  ForkJoinPool.managedBlock(new DoLockInterruptibly());
}

代码示例来源:origin: com.github.robozonky/robozonky-common

static <Y, Z> Z call(final Function<Y, Z> function, final Y proxy) {
  LOGGER.trace("Executing...");
  final BlockingOperation<Z> operation = new BlockingOperation<>(() -> function.apply(proxy));
  try {
    ForkJoinPool.managedBlock(operation);
  } catch (final InterruptedException ex) {
    LOGGER.debug("Remote operation interrupted.", ex);
    Thread.currentThread().interrupt();
  } finally {
    LOGGER.trace("... done.");
  }
  return operation.getResult();
}

代码示例来源:origin: RoboZonky/robozonky

static <Y, Z> Z call(final Function<Y, Z> function, final Y proxy) {
  LOGGER.trace("Executing...");
  final BlockingOperation<Z> operation = new BlockingOperation<>(() -> function.apply(proxy));
  try {
    ForkJoinPool.managedBlock(operation);
  } catch (final InterruptedException ex) {
    LOGGER.debug("Remote operation interrupted.", ex);
    Thread.currentThread().interrupt();
  } finally {
    LOGGER.trace("... done.");
  }
  return operation.getResult();
}

代码示例来源:origin: kabutz/javaspecialists

public boolean tryLock(long time, TimeUnit unit)
    throws InterruptedException {
  // If we already have the lock, then the TryLocker will
  // immediately acquire the lock due to reentrancy.  We do not
  // really care whether we had a timeout inside the TryLocker,
  // but only want to return whether or not we hold the lock
  // at the end of the method.
  ForkJoinPool.managedBlock(new TryLocker(time, unit));
  return isHeldByCurrentThread();
}

代码示例来源:origin: kabutz/javaspecialists

public void lock() {
  DoLock locker = new DoLock(); // we want to create this
  // before passing it into the lambda, to prevent it from
  // being created again if the thread is interrupted for some
  // reason
  Interruptions.saveForLater(
      () -> ForkJoinPool.managedBlock(locker));
}

代码示例来源:origin: hypercube1024/firefly

public static <T> T callInManagedBlock(final Supplier<T> supplier) {
  final SupplierManagedBlock<T> managedBlock = new SupplierManagedBlock<>(supplier);
  try {
    ForkJoinPool.managedBlock(managedBlock);
  } catch (InterruptedException e) {
    throw new CommonRuntimeException(e);
  }
  return managedBlock.getResult();
}

代码示例来源:origin: com.fireflysource/firefly-common

public static <T> T callInManagedBlock(final Supplier<T> supplier) {
  final SupplierManagedBlock<T> managedBlock = new SupplierManagedBlock<>(supplier);
  try {
    ForkJoinPool.managedBlock(managedBlock);
  } catch (InterruptedException e) {
    throw new CommonRuntimeException(e);
  }
  return managedBlock.getResult();
}

代码示例来源:origin: groupon/monsoon

public void waitAvail() throws InterruptedException {
  synchronized (this) {
    if (nextAvail() || atEnd()) return;
  }
  final WakeupListener w = new WakeupListener(() -> nextAvail() || atEnd());
  setWakeup(w::wakeup);
  ForkJoinPool.managedBlock(w);
}

相关文章

微信公众号

最新文章

更多

ForkJoinPool类方法