/**
* Returns the {@link Executor} that will be used to run this service.Subclasses may override this method to use a custom {@link Executor}, which may configure its worker thread with a specific name, thread group or priority. The returned executor's {@link Executor#execute(Runnable) execute()} method is called when this service is started, and should returnpromptly.
*/
protected Executor executor(){
return new Executor(){
public void execute( Runnable command){
new Thread(command,AbstractExecutionThreadService.this.toString()).start();
}
}
;
}

/**
* Returns the {@link Executor} that will be used to run this service.Subclasses may override this method to use a custom {@link Executor}, which may configure its worker thread with a specific name, thread group or priority. The returned executor's {@link Executor#execute(Runnable) execute()} method is called when this service is started, and should returnpromptly.
*/
protected Executor executor(){
return new Executor(){
public void execute( Runnable command){
new Thread(command,AbstractExecutionThreadService.this.toString()).start();
}
}
;
}

Example 25

From project platform_frameworks_support, under directory /volley/src/com/android/volley/.

/**
* Start the worker pool processing events in sequence.
* @param executor providing threads for running the workers.
* @return the {@link RingBuffer} used for the work queue.
* @throws IllegalStateException is the pool has already been started and not halted yet
*/
public RingBuffer<T> start(final Executor executor){
if (!started.compareAndSet(false,true)) {
throw new IllegalStateException("WorkerPool has already been started and cannot be restarted until halted.");
}
final long cursor=ringBuffer.getCursor();
workSequence.set(cursor);
for ( WorkProcessor<?> processor : workProcessors) {
processor.getSequence().set(cursor);
executor.execute(processor);
}
return ringBuffer;
}

Example 36

From project elasticsearch-cloud-aws, under directory /src/main/java/org/elasticsearch/cloud/aws/blobstore/.

/**
* Executes the task with the specified parameters. The task returns itself (this) so that the caller can keep a reference to it. <p>This method is typically used with {@link #THREAD_POOL_EXECUTOR} toallow multiple tasks to run in parallel on a pool of threads managed by AsyncTask, however you can also use your own {@link Executor} for custombehavior. <p><em>Warning:</em> Allowing multiple tasks to run in parallel from a thread pool is generally <em>not</em> what one wants, because the order of their operation is not defined. For example, if these tasks are used to modify any state in common (such as writing a file due to a button click), there are no guarantees on the order of the modifications. Without careful work it is possible in rare cases for the newer version of the data to be over-written by an older one, leading to obscure data loss and stability issues. Such changes are best executed in serial; to guarantee such work is serialized regardless of platform version you can use this function with {@link #SERIAL_EXECUTOR}. <p>This method must be invoked on the UI thread.
* @param exec The executor to use. {@link #THREAD_POOL_EXECUTOR} is available as aconvenient process-wide thread pool for tasks that are loosely coupled.
* @param params The parameters of the task.
* @return This instance of AsyncTask.
* @throws IllegalStateException If {@link #getStatus()} returns either{@link AsyncTask.Status#RUNNING} or {@link AsyncTask.Status#FINISHED}.
*/
@SuppressWarnings("javadoc") public final AsyncTask<Params,Progress,Result> executeOnExecutor(Executor exec,Params... params){
if (mStatus != Status.PENDING) {
switch (mStatus) {
case RUNNING:
throw new IllegalStateException("Cannot execute task:" + " the task is already running.");
case FINISHED:
throw new IllegalStateException("Cannot execute task:" + " the task has already been executed " + "(a task can be executed only once)");
}
}
mStatus=Status.RUNNING;
onPreExecute();
mWorker.mParams=params;
exec.execute(mFuture);
return this;
}

Example 46

From project Metamorphosis, under directory /metamorphosis-client/src/test/java/com/taobao/metamorphosis/client/consumer/.