Executes the task in the given {@link ComThread}
@param t the ComThread to execute the task
@return the return value of the Task execution (returned by {@link #call()}).
18908
public final T execute(ComThread t) {
        if(Thread.currentThread()==t)
            // if invoked from within ComThread, execute it at once
            return call();
        else
            // otherwise schedule the execution and block
            return t.execute(this);
    }
460136
protected ThreadFactory getThreadFactory() {
        return new ThreadFactory() {
            private final ThreadFactory parent = Executors.defaultThreadFactory();
            private final AtomicInteger tid = new AtomicInteger(1);

            @Override
            public Thread newThread(final Runnable task) {
              final Thread t = parent.newThread(task);
              t.setName(THREAD_PREFIX + tid.getAndIncrement());
              return t;
            }
          };
    }
1093851
public boolean scheduleExecutorTask(Runnable task)
  {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    synchronized (_executorLock) {
      _executorTaskCount++;

      if (_executorTaskCount <= _executorTaskMax || _executorTaskMax < 0) {
        boolean isPriority = false;
        boolean isQueue = true;
        boolean isWake = true;

        return scheduleImpl(task, loader, MAX_EXPIRE, isPriority, isQueue, isWake);
      }
      else {
        ExecutorQueueItem item = new ExecutorQueueItem(task, loader);

        if (_executorQueueTail != null)
          _executorQueueTail._next = item;
        else
          _executorQueueHead = item;

        _executorQueueTail = item;

        return false;
      }
    }
  }
723853
@SuppressWarnings("unchecked")
    public boolean execute(Runnable r) {
    	
    	try {
			queue[queue_no++ % nThreads].putFirst(r);
			if (queue_no == nThreads){
				queue_no = 0;
			}
            return true;
		} catch (InterruptedException e) {
            String info = "Failed to enqueue task: ";
            Throwable baseCause = org.gautelis.vopn.lang.Stacktrace.getBaseCause(e);
            info += baseCause.getMessage();
            log.warn(info, e);
		}
        return false;
    }
921145
public <T extends Runnable> T executeAsync(T runnable) {
		synchronized (this.tasks) {
			this.tasks.add(runnable);
			// Notify that a task has been added
			this.tasks.notifyAll();

			if (this.tasks.size() == 1) {
				this.onTaskBecameNotEmpty();
			}

			this.onTaskAdded();
		}
		return runnable;
	}
533871
<T> T runInCompilerThread(Callable<T> callable) {
    return compilerExecutor.runInCompilerThread(
        callable, options != null && options.getTracerMode().isOn());
  }
834587
public LatchedLazyFuture<X> withRunningThread() {
        if (state.get() == DONE) return this;
        if (state.compareAndSet(null, STARTED)) {
            Thread thread = new Thread(this.getClass().getName() + ".withRunningThread") {
                @Override
                public void run() {
                    try {
                        internalCalc();
                    } catch (ExecutionException | InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
            thread.start();

            return this;
        } else {
            return this;
        }
    }
866018
public <TContinuationResult> Task<TContinuationResult> onSuccessTask(
      final Continuation<TResult, Task<TContinuationResult>> continuation) {
    return onSuccessTask(continuation, IMMEDIATE_EXECUTOR);
  }
1310675
public void abort(Throwable t) {
        // Set the result to the given exception
        boolean abortSuccessful = getResultFuture().completeExceptionally(t);

        if (abortSuccessful) {
            // Attempt to abort the task
            getTaskFuture().cancel(true);
        }
    }
835838
@SuppressWarnings("unchecked")
  public static <TResult> Task<TResult> forResult(TResult value) {
    if (value == null) {
      return (Task<TResult>) TASK_NULL;
    }
    if (value instanceof Boolean) {
      return (Task<TResult>) ((Boolean) value ? TASK_TRUE : TASK_FALSE);
    }
    bolts.TaskCompletionSource<TResult> tcs = new bolts.TaskCompletionSource<>();
    tcs.setResult(value);
    return tcs.getTask();
  }
792346
private int doInvoke() {
        int s; Thread t; ForkJoinWorkerThread wt;
        if ((s = doExec()) >= 0) {
            if ((t = Thread.currentThread()) instanceof ForkJoinWorkerThread)
                s = (wt = (ForkJoinWorkerThread)t).pool.awaitJoin(wt.workQueue,
                                                                  this);
            else
                s = externalAwaitDone();
        }
        return s;
    }
1322940
public static Thread getThread(Runnable runnable, String name){
        return doThread(runnable, name, DefaultThreadDeamon);
    }
1130525
public static Callable<Object> callable(Runnable task) {
        if (task == null)
            throw new NullPointerException();
        return new RunnableAdapter<Object>(task, null);
    }
742295
public String execute(String clientID, String name, long time, Level level,
	        Object message, Throwable throwable){
		return Thread.currentThread().getName();
	}
1255681
public static void main(String[] args) {

        ArrayList<String> tmpArgs = new ArrayList<String>(Arrays.asList(args));
        
        // Get number of threads for multithreading mode
        int numThreads = 1;
        for (int i=0; i<tmpArgs.size()-1; i++) {
        	if (tmpArgs.get(i).equals("-t")) {
        		try {
        			numThreads = Integer.parseInt(tmpArgs.get(i+1));
        			tmpArgs.remove(i+1);
        			tmpArgs.remove(i);
        		} catch (NumberFormatException e) {
        			System.err.println("Invalid number of threads.");
        			System.err.println(e.getStackTrace());
        		}
        	}
        }
        logger.info("Number of threads:{}", numThreads);
        
        args = tmpArgs.toArray(new String[0]);

        StringBuilder cliString = new StringBuilder();
        for (int i = 0; i < args.length; i++) {
            cliString.append(" ").append(args[i]);
        }
        logger.debug("Command line string = {}", cliString.toString());
        System.out.println("Command line string = " + cliString.toString());

        Task task = null;
        try {
            task = (Task) ClassOption.cliStringToObject(cliString.toString(), Task.class, null);
            logger.info("Sucessfully instantiating {}", task.getClass().getCanonicalName());
        } catch (Exception e) {
            logger.error("Fail to initialize the task", e);
            System.out.println("Fail to initialize the task" + e);
            return;
        }
        task.setFactory(new ThreadsComponentFactory());
        task.init();
        
        ThreadsEngine.submitTopology(task.getTopology(), numThreads);
    }
1168245
@Override
    protected void afterExecute(Runnable r, Throwable t) {
        super.afterExecute(r, t);
        if (t == null && r instanceof Future<?>) {
            try {
                ((Future<?>) r).get();
            } catch (CancellationException ce) {
                t = ce;
            } catch (ExecutionException ee) {
                t = ee.getCause();
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt(); // ignore/reset
            }
        }
        if (t != null) {
            ARouter.logger.warning(Consts.TAG, "Running task appeared exception! Thread [" + Thread.currentThread().getName() + "], because [" + t.getMessage() + "]\n" + TextUtils.formatStackTrace(t.getStackTrace()));
        }
    }
1072317
@Override
    public Thread newThread(final Runnable r) {
        final Thread t = new Thread(r, threadNamePrefix + threadIdx.getAndIncrement());
        t.setDaemon(daemon);
        return t;
    }