Wraps a {@code Runnable} for submission to the underlying executor. The
default implementation delegates to {@link #wrapTask(Callable)}.
774356
protected Runnable wrapTask(Runnable command) {
    final Callable<Object> wrapped = wrapTask(
        Executors.callable(command, null));
    return new Runnable() {
      @Override public void run() {
        try {
          wrapped.call();
        } catch (Exception e) {
          Throwables.propagate(e);
        }
      }
    };
  }
499294
public void runIntoJTP(final JRebirthRunnable runnable) {

        if (getFacade().executorService().checkAvailability(runnable.priority())) {
            getFacade().executorService().execute(runnable);
            LOGGER.log(JTP_QUEUED, runnable.toString());
        } else {
            getFacade().highPriorityExecutorService().execute(runnable);
            LOGGER.log(HPTP_QUEUED, runnable.toString());
        }

    }
273607
@SuppressWarnings("static-method")
	protected Runnable createTask(Runnable runnable) {
		if (runnable instanceof JanusRunnable) {
			return runnable;
		}
		return new JanusRunnable(runnable);
	}
865573
public static void call(Runnable task) {
        try {
            call(() -> {
                task.run();
                return true;
            });
        } catch (Exception e) {
            // It's safe to throw unsafely here because the Callable we passed never throws a checked exception.
            Exceptions.throwUnsafely(e);
        }
    }
218547
public <T extends Runnable> T executeSync(T runnable) {
		synchronized (runnable) {
			this.executeAsync(runnable);
			try {
				runnable.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		return runnable;
	}
546294
private void runInMainThread(Runnable runnable) {
        if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
            mHandler.post(runnable);
        } else {
            runnable.run();
        }
    }
677462
public Future<?> submit(Runnable task)
    {
        Preconditions.checkState(isOpen.get(), "CloseableExecutorService is closed");

        InternalFutureTask<Void> futureTask = new InternalFutureTask<Void>(new FutureTask<Void>(task, null));
        executorService.execute(futureTask);
        return futureTask;
    }
318299
public static <E extends Throwable> @NonNull Runnable rethrowRunnable(final @NonNull ThrowingRunnable<E> runnable) {
    return runnable;
  }
1328214
public <T> Future<T> submit(Callable<T> callable) {
		checkThreadQueue();
		return threadPool.submit(callable);
	}
942035
protected <T> Future<T> invokeSubmit(ExecutorService executor, Callable<T> task) {
    return executor.submit(wrapTask(task));
  }
35622
protected final void runOnUiThread(@NonNull Runnable runnable) {
        checkNotNull(runnable, "runnable");
        if (Looper.myLooper() == Looper.getMainLooper()) {
            runnable.run();
        } else {
            mPoster.post(runnable);
        }
    }
416648
public Runnable asRunnable() {
        return new Runnable() {
            @Override
            public void run() {
                try {
                    callable.call();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        };
    }
349618
protected <T> Callable<T> wrapTask(Callable<T> task) {
    // Preserve the MDC context of the caller thread.
    Map contextMap = MDC.getCopyOfContextMap();
    if (contextMap != null) {
      return new MDCCallableAdapter(task, contextMap);
    }
    return task;
  }
601384
@Override
  public Runnable wrap(Runnable runnable) {
    if (isTracing()) {
      return new SpanContinuingTraceRunnable(this, this.traceKeys, this.spanNamer, runnable);
    }
    return runnable;
  }
1219275
public void execute(final T runnable) {
        synchronized (queue) {
            if (runnable != null && !disabled) {
                queue.addLast(runnable);
                queue.notify();
                System.out.println("WorkQueue has added runable - WorkQueue size is " + queue.size());
            }
        }
    }
1332171
static <T extends RemoteRunnable> T runOnH2ONode(H2ONode node, T runnable) {
    if (node == H2O.SELF) {
      // run directly
      runnable.run();
      return runnable;
    } else {
      RunnableWrapperTask<T> task = new RunnableWrapperTask<>(runnable);
      try {
        return new RPC<>(node, task).call().get()._runnable;
      } catch (DistributedException e) {
        Log.trace("Exception in calling runnable on a remote node",  e);
        Throwable cause = e.getCause();
        throw cause instanceof RuntimeException ? (RuntimeException) cause : e;
      }
    }
  }
706076
@Override
    public Thread newThread(final Runnable runnable) {
        Runnable wrapped = new Runnable() {
            @Override
            public void run() {
                try {
                    // As the runnable is wrapped in another runnable object, we call the run method directly.
                    runnable.run();     //NOSONAR
                } catch (Exception e) {  //NOSONAR
                    // Catching exception is acceptable here as the wrapped runnable can throw almost anything.
                    log.error("Error while executing " + Thread.currentThread().getName(), e);
                }
            }
        };
        Thread thread = factory.newThread(wrapped);
        thread.setName(prefix + "-" + thread.getName());
        return thread;
    }