Search this API

y.util
Class TaskExecutorFactory

java.lang.Object
  extended by y.util.TaskExecutorFactory
Direct Known Subclasses:
MultiThreadedTaskExecutorFactory

public abstract class TaskExecutorFactory
extends java.lang.Object

Base factory class for creating TaskExecutor instances. Use setDefault(TaskExecutorFactory) to set a specific factory implementation to be used by algorithms which support multi-threaded execution.

 

Field Summary
static TaskExecutorFactory DEFAULT
          Shared instance of the default TaskExecutorFactory.
static TaskExecutorFactory MULTI_THREADED
          Shared instance of a TaskExecutorFactory that creates TaskExecutors that execute tasks in parallel, i.e., multi-threaded.
static TaskExecutorFactory SINGLE_THREADED
          Shared instance of a TaskExecutorFactory that creates TaskExecutors that execute tasks in a single thread, i.e., one after another.
 
Constructor Summary
TaskExecutorFactory()
           
 
Method Summary
abstract  TaskExecutor createExecutor()
          Creates a new TaskExecutor.
static TaskExecutorFactory getDefault()
          Returns the factory used to create new TaskExecutors.
static void setDefault(TaskExecutorFactory factory)
          Sets the factory used to create new TaskExecutors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final TaskExecutorFactory DEFAULT
Shared instance of the default TaskExecutorFactory.

This factory does not actually create TaskExecutor instances, but delegates instance creation to a dynamically determined factory. This is done as follows: First, this factory tries to load a factory that is declared as service provider in META-INF/services (see ServiceRegistry for details). If there are multiple provider implementations available, one is chosen randomly. If loading a service provider fails, then this factory tries to load MultiThreadedTaskExecutorFactory via reflection. If loading MultiThreadedTaskExecutorFactory fails, too, the MULTI_THREADED factory instance is used.


SINGLE_THREADED

public static final TaskExecutorFactory SINGLE_THREADED
Shared instance of a TaskExecutorFactory that creates TaskExecutors that execute tasks in a single thread, i.e., one after another.


MULTI_THREADED

public static final TaskExecutorFactory MULTI_THREADED
Shared instance of a TaskExecutorFactory that creates TaskExecutors that execute tasks in parallel, i.e., multi-threaded. The number of created threads is limited by the minimum of the size of the given task list (see method TaskExecutor.execute(java.util.List)) and the number of available processors as returned by method java.lang.Runtime.getRuntime().availableProcessors().

Constructor Detail

TaskExecutorFactory

public TaskExecutorFactory()
Method Detail

getDefault

public static TaskExecutorFactory getDefault()
Returns the factory used to create new TaskExecutors. By default, DEFAULT is returned.

Returns:
The factory used to create new TaskExecutor.

setDefault

public static void setDefault(TaskExecutorFactory factory)
Sets the factory used to create new TaskExecutors.

Parameters:
factory - The factory used to create new TaskExecutor.

createExecutor

public abstract TaskExecutor createExecutor()
Creates a new TaskExecutor.

Returns:
A new TaskExecutor.

© Copyright 2000-2017,
yWorks GmbH.
All rights reserved.