Android Open Source - task4java Task Factory






From Project

Back to project page task4java.

License

The source code is released under:

Apache License

If you think the Android project task4java listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *  Copyright (c) 2014 Andree Hagelstein, Maik Schulze, Deutsche Telekom AG. All Rights Reserved.
 *  // w w w.  j av  a  2  s  .c  o m
 *  Filename: TaskFactory.java
 */
package com.task4java.util.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * A factory for creating {@link Task} objects.
 */
public class TaskFactory {

  /** The default executor service for the {@link Task}. */
  public static ExecutorService defaultExecutorService = Executors.newCachedThreadPool();
  
  /** The background executor service. */
  public static ExecutorService backgroundExecutorService = Executors.newFixedThreadPool(4);
  
  /** The image executor service. */
  public static ExecutorService imageExecutorService = Executors.newFixedThreadPool(2);
  
  /** The callback function to retrieve exceptions from the {@link Task}. */
  public static CallableValue<Void, TaskException> unhandledExceptions;

  /**
   * Creates and starts a new {@code Task}.
   *
   * @param <V> the value type
   * @param callable the callable
   * @return the task
   */
  public static <V> Task<V> startNew(Callable<V> callable) {
    
      return startNew(callable, "");
  }

  /**
   * Creates and starts a new {@code Task}.
   *
   * @param <V> the value type
   * @param callable the callable
   * @param id the id
   * @return the task
   */
  public static <V> Task<V> startNew(Callable<V> callable, String id) {
        
      Task<V> task = new Task<V>(callable, id);
        task.start();

        return task;
    }
  
  /**
   * Creates and starts a new {@code Task}.
   *
   * @param <V> the value type
   * @param callable the callable
   * @param executor the executor
   * @return the task
   */
  public static <V> Task<V> startNew(Callable<V> callable, Executor executor) {
    
    return startNew(callable, executor, "");
  }
  
  /**
   * Creates and starts a new {@code Task}.
   *
   * @param <V> the value type
   * @param callable the callable
   * @param executor the executor
   * @param id the id
   * @return the task
   */
  public static <V> Task<V> startNew(Callable<V> callable, Executor executor, String id) {
        
        Task<V> task = new Task<V>(callable, executor, id);
        task.start();

        return task;
    }

  /**
   * Shutdown.
   */
  public static void shutdown() {
    
    defaultExecutorService.shutdown();
    backgroundExecutorService.shutdown();
    imageExecutorService.shutdown();
  }
}




Java Source Code List

com.task4java.IndexedList.java
com.task4java.KeyValuePair.java
com.task4java.Stopwatch.java
com.task4java.StringUtils.java
com.task4java.Tuple.java
com.task4java.android.activity.ActivityUtils.java
com.task4java.android.activity.BaseActivity.java
com.task4java.android.annotation.Annotations.java
com.task4java.android.examples.App.java
com.task4java.android.examples.activity.AboutActivity.java
com.task4java.android.examples.activity.ExpandableListAdapter.java
com.task4java.android.examples.activity.MainActivity.java
com.task4java.android.examples.activity.WelcomeActivity.java
com.task4java.android.examples.backend.AndroidServiceClient.java
com.task4java.android.util.concurrent.ActivityExecutor.java
com.task4java.android.util.concurrent.HandlerExecutor.java
com.task4java.data.backend.IServiceClient.java
com.task4java.data.backend.ServiceClient.java
com.task4java.data.backend.model.MainMenuAnnotation.java
com.task4java.data.frontend.ApplicationClient.java
com.task4java.data.frontend.model.MainMenuItemGroupList.java
com.task4java.data.frontend.model.MainMenuItemGroup.java
com.task4java.data.frontend.model.MainMenuItem.java
com.task4java.http.HttpHeaders.java
com.task4java.http.HttpMimeTypes.java
com.task4java.http.HttpRequestMethods.java
com.task4java.http.HttpStatusCodes.java
com.task4java.http.client.HttpContent.java
com.task4java.http.client.HttpStringContent.java
com.task4java.http.client.IImageClient.java
com.task4java.http.client.IRestClient.java
com.task4java.http.client.ImageClientGingerbread.java
com.task4java.http.client.ImageClient.java
com.task4java.http.client.ImageResponse.java
com.task4java.http.client.RestClientGingerbread.java
com.task4java.http.client.RestClient.java
com.task4java.http.client.RestResponse.java
com.task4java.lang.reflect.ReflectionCache.java
com.task4java.net.URLBuilder.java
com.task4java.util.concurrent.CallableTask.java
com.task4java.util.concurrent.CallableValue2.java
com.task4java.util.concurrent.CallableValue.java
com.task4java.util.concurrent.ITaskStart.java
com.task4java.util.concurrent.ITask.java
com.task4java.util.concurrent.TaskCompletionSource.java
com.task4java.util.concurrent.TaskContinuationOptions.java
com.task4java.util.concurrent.TaskException.java
com.task4java.util.concurrent.TaskFactory.java
com.task4java.util.concurrent.TaskResultException.java
com.task4java.util.concurrent.TaskStartException.java
com.task4java.util.concurrent.Task.java
com.task4java.util.log.ConsoleLogger.java
com.task4java.util.log.ILog.java
com.task4java.util.log.Logger.java