Run the task into the appropriated thread.

@param runInto the targeted thread
@param runnable the task to run
@param timeout the optional timeout value after which the thread will be released (default is 1000 ms)
336025
public static void run(final RunType runInto, final JRebirthRunnable runnable, final long... timeout) {
        switch (runInto) {
            case JAT:
                runIntoJAT(runnable);
                break;
            case JAT_SYNC:
                runIntoJATSync(runnable, timeout);
                break;
            case JIT:
                runIntoJIT(runnable);
                break;
            case JIT_SYNC:
                runIntoJITSync(runnable, timeout);
                break;
            case JTP:
                runIntoJTP(runnable);
                break;
            case JTP_SYNC:
                runIntoJTPSync(runnable, timeout);
                break;
            case SAME:
            default:
                runnable.run();
        }
    }
133895
protected void scheduleRunAsync(Runnable runnable, Time delay) {
		scheduleRunAsync(runnable, delay.getSize(), delay.getUnit());
	}
595245
public static void asyncExecute(Runnable runnable) {
		if (runnable != null) {
			try {
				Para.getExecutorService().execute(runnable);
			} catch (RejectedExecutionException ex) {
				logger.warn(ex.getMessage());
				try {
					runnable.run();
				} catch (Exception e) {
					logger.error(null, e);
				}
			}
		}
	}
532896
private void startNewReconstituteThread(Runnable runnable) throws InterruptedException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "startNewReconstituteThread");

        if (_reconstituteThreadpool == null)
        {
            createReconstituteThreadPool();
        }

        _reconstituteThreadpool.execute(runnable);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "startNewReconstituteThread");
    }
33093
@Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                int count = collectionService.commitAnnotations(ANNOTATION_CHUNK_SIZE, TIMEOUT);

                if (count > 0) {
                    LOGGER.info(MessageFormat.format("Committed {0} annotations.", count));
                    jobCounter.addAndGet(count);
                }
                Thread.sleep(POLL_INTERVAL_MS);
            } catch (InterruptedException ie) {
                LOGGER.info("Execution was interrupted.");
                Thread.currentThread().interrupt();
                break;
            } catch (Throwable ex) {
                LOGGER.info("Error occurred while committing annotations. Reason {}", ex.toString());
            }
        }
        LOGGER.warn(MessageFormat.format("Annotation committer thread interrupted. {} annotations committed by this thread.", jobCounter.get()));
        collectionService.dispose();
        monitorService.dispose();
    }
1107271
@Override
  public void execute(Runnable runnable) {
    if (runnable == null) {
      throw new NullPointerException("runnable parameter is null");
    }

    if (!mWorkQueue.offer(runnable)) {
      throw new RejectedExecutionException(
          mName + " queue is full, size=" + mWorkQueue.size());
    }

    final int queueSize = mWorkQueue.size();
    final int maxSize = mMaxQueueSize.get();
    if ((queueSize > maxSize) && mMaxQueueSize.compareAndSet(maxSize, queueSize)) {
      FLog.v(TAG, "%s: max pending work in queue = %d", mName, queueSize);
    } // else, there was a race and another thread updated and logged the max queue size

    startWorkerIfNeeded();
  }
188341
protected void runOnGUIThreadIfExistsOtherwiseRunDirect(Runnable runnable) {
        if(getTextGUI() != null && getTextGUI().getGUIThread() != null) {
            getTextGUI().getGUIThread().invokeLater(runnable);
        }
        else {
            runnable.run();
        }
    }
1163682
@Override
    public void invoke(CheckedRunnable runnable) {
        try {
            super.invoke(runnable);
        } catch (Exception ex) {
            LOGGER.debug("Catched exception, suppressing", ex);
        }
    }
962457
protected void executeOnGdx (final Runnable runnable) {
		final CountDownLatch latch = new CountDownLatch(1);

		final AtomicReference<Exception> exceptionAt = new AtomicReference<Exception>();

		Gdx.app.postRunnable(new Runnable() {
			@Override
			public void run () {
				try {
					runnable.run();
				} catch (Exception e) {
					exceptionAt.set(e);
				} finally {
					latch.countDown();
				}
			}
		});

		try {
			latch.await();

			final Exception e = exceptionAt.get();
			if (e != null) {
				failed(e);
			}
		} catch (InterruptedException e) {
			failed(e);
		}
	}
209384
private void invokeAndWait(Runnable run) {
        if(!SwingUtilities.isEventDispatchThread()) {
            try {
                SwingUtilities.invokeAndWait(run);
            } catch(Exception e) {
                // shouldn't happen
                e.printStackTrace();
            }
        } else {
            run.run();
        }
    }
296247
public static void step(final ThrowableContextRunnableVoid<StepContext> runnable) {
        step(step -> {
            runnable.run(step);
            return null;
        });
    }
446156
private void checkRunnable(Class<?> type) {
    if(Runnable.class.isAssignableFrom(type)) {
      try{
        this.method = type.getMethod("run");
      } catch(Exception e) {
        throw new RuntimeException("Cannot get run method of runnable class.", e);
      }
    }
  }
261107
@Override
	public void executeOnUIThread(Runnable runnable) {
		Activity activity = fragment.getActivity();
		if (activity != null && !activity.isDestroyed()) {
			activity.runOnUiThread(new SafeExecuteWrapperRunnable(fragment, runnable));
		}
	}
960104
public void run(Runnable runnable, Executor executor)
    {
        if (this.goForward())
        {
            for (int i = this.from; i <= this.to; i += this.step)
            {
                executor.execute(runnable);
            }
        }
        else
        {
            for (int i = this.from; i >= this.to; i += this.step)
            {
                executor.execute(runnable);
            }
        }
    }
77653
public final <T> T executeInTransaction(final Runnable<T> runnable) throws Exception {
        return executeInTransaction(runnable, true);
    }
977140
@Override
    public void run(Context context) throws IOException, InterruptedException {
        outer = context;
        int numberOfThreads = getThreadCount(context);
        mapClass = getMapperClass(context);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Running with " + numberOfThreads + " threads");
        }        
        // current mapper takes 1 thread
        numberOfThreads--;
        
        InputSplit split = context.getInputSplit();

        // submit runners
        try {
	        List<Future<?>> taskList = null;
	        if (threadPool != null) {
            	taskList = new ArrayList<Future<?>>();
                synchronized (threadPool) {
                    for (int i = 0; i < numberOfThreads; ++i) {
                        MapRunner runner = new MapRunner();
                        BaseMapper<K1,V1,K2,V2> mapper = runner.getMapper();
                        if (!threadPool.isShutdown()) {
                            Collection<Future<Object>> tasks = 
                                mapper.submitTasks(threadPool, split);
                            taskList.addAll(tasks);
                            numberOfThreads -= tasks.size();
                            Future<?> future = threadPool.submit(runner);
                            taskList.add(future);	                        
                        } else {
                            throw new InterruptedException(
                                "Thread Pool has been shut down");
                        }
                    }
                    threadPool.notify();
                }
	            
                // MapRunner that runs in current thread
                MapRunner r = new MapRunner();
                r.run();
    
                for (Future<?> f : taskList) {
                    f.get();
                }
	        } else {
	            runners = new ArrayList<MapRunner>(numberOfThreads);
                for (int i = 0; i < numberOfThreads; ++i) {
                    MapRunner thread;
                    thread = new MapRunner();
                    thread.start();
                    runners.add(i, thread);
                }
                // MapRunner runs in current thread
                MapRunner r = new MapRunner();
                r.run();
                
                for (int i = 0; i < numberOfThreads; ++i) {
                    MapRunner thread = runners.get(i);
                    thread.join();
                    Throwable th = thread.throwable;
                    if (th != null) {
                        if (th instanceof IOException) {
                            throw (IOException) th;
                        } else if (th instanceof InterruptedException) {
                            throw (InterruptedException) th;
                        } else {
                            throw new RuntimeException(th);
                        }
                    }
                }
            }       
        } catch (ClassNotFoundException e) {
            LOG.error("MapRunner class not found", e);
        } catch (ExecutionException e) {
        	LOG.error("Error waiting for MapRunner threads to complete", e);
		}        
    }
367468
public void addTaskRunOnce(int startDelayTime, Runnable runnable) {
        scheduledExecutorService.schedule(runnable, startDelayTime, TimeUnit.SECONDS);
    }