Top Description Fields Constructors Methods
javafx.concurrent

public abstract Class Service<V>

extends Object
implements Worker<V>, EventTarget
Class Inheritance
All Implemented Interfaces
javafx.event.EventTarget, javafx.concurrent.Worker
Known Direct Subclasses
javafx.concurrent.ScheduledService
Type Parameters
<V>
the type of object returned by the Service
Imports
javafx.application.Platform, javafx.beans.property.BooleanProperty, .DoubleProperty, .ObjectProperty, .ReadOnlyBooleanProperty, .ReadOnlyDoubleProperty, .ReadOnlyObjectProperty, .ReadOnlyStringProperty, .SimpleBooleanProperty, .SimpleDoubleProperty, .SimpleObjectProperty, .SimpleStringProperty, .StringProperty, javafx.event.Event, .EventDispatchChain, .EventHandler, .EventTarget, .EventType, java.util.concurrent.BlockingQueue, .Executor, .LinkedBlockingQueue, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit, com.sun.javafx.logging.PlatformLogger

A Service is a non-visual component encapsulating the information required to perform some work on one or more background threads. As part of the JavaFX UI library, the Service knows about the JavaFX Application thread and is designed to relieve the application developer from the burden of managing multithreaded code that interacts with the user interface. As such, all of the methods and state on the Service are intended to be invoked exclusively from the JavaFX Application thread. The only exception to this is when initially configuring a Service, which may safely be done from any thread, and initially starting a Service, which may also safely be done from any thread. However, once the Service has been initialized and started, it may only thereafter be used from the FX thread.

A Service creates and manages a Task that performs the work on the background thread. Service implements Worker. As such, you can observe the state of the background task and optionally cancel it. Service is a reusable Worker, meaning that it can be reset and restarted. Due to this, a Service can be constructed declaratively and restarted on demand. Once a Service is started, it will schedule its Task and listen for changes to the state of the Task. A Task does not hold a reference to the Service that started it, meaning that a running Task will not prevent the Service from being garbage collected.

If an java.util.concurrent.Executor is specified on the Service, then it will be used to actually execute the service. Otherwise, a daemon thread will be created and executed. If you wish to create non-daemon threads, then specify a custom Executor (for example, you could use a ThreadPoolExecutor with a custom java.util.concurrent.ThreadFactory).

Because a Service is intended to simplify declarative use cases, subclasses should expose as properties the input parameters to the work to be done. For example, to write a Service that reads the first line from any URL and returns it as a String, it might be defined with a single property, url, and might be implemented as:


    public static class FirstLineService extends Service<String> {
        private StringProperty url = new SimpleStringProperty(this, "url");
        public final void setUrl(String value) { url.set(value); }
        public final String getUrl() { return url.get(); }
        public final StringProperty urlProperty() { return url; }

        protected Task createTask() {
            final String _url = getUrl();
            return new Task<String>() {
                protected String call() throws Exception {
                    URL u = new URL(_url);
                    BufferedReader in = new BufferedReader(
                            new InputStreamReader(u.openStream()));
                    String result = in.readLine();
                    in.close();
                    return result;
                }
            };
        }
    }
    

The Service by default uses a ThreadPoolExecutor with some unspecified default or maximum thread pool size. This is done so that naive code will not completely swamp the system by creating thousands of Threads.

Since
JavaFX 2.0

Field Summary

Modifier and TypeField and Description
private EventHelper
private final ObjectProperty<Throwable>
private static final ThreadPoolExecutor
private final ObjectProperty<Executor>
executor

The executor to use for running this Service.

private static final BlockingQueue<Runnable>
IO_QUEUE

Because the ThreadPoolExecutor works completely backwards from what we want (ie: it doesn't increase thread count beyond the core pool size unless the queue is full), our queue has to be smart in that it will REJECT an item in the queue unless the thread size in the EXECUTOR is > 32, in which case we will queue up.

private static final PlatformLogger
LOG

Logger used in the case of some uncaught exceptions

private final StringProperty
private final DoubleProperty
private final BooleanProperty
private volatile boolean
startedOnce

This boolean is set to true once the Service has been initially started.

private final ObjectProperty<Worker.State>
private Task<V>
task

A reference to the last task that was executed.

private static final ThreadFactory
private static final ThreadGroup
private static final int
private static final long
private final StringProperty
private final DoubleProperty
private static final Thread.UncaughtExceptionHandler
private final ObjectProperty<V>
private final DoubleProperty

Constructor Summary

AccessConstructor and Description
protected
Service()

Create a new Service.

Method Summary

Modifier and TypeMethod and Description
public final <T extends Event> void
addEventFilter(final EventType<T> eventType, final EventHandler<? super T> eventFilter)

Overrides default javafx.event.EventTarget.addEventFilter.

Registers an event filter for this target.

public final <T extends Event> void
addEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)

Overrides default javafx.event.EventTarget.addEventHandler.

Registers an event handler for this target.

public EventDispatchChain
buildEventDispatchChain(EventDispatchChain tail)

Implements javafx.event.EventTarget.buildEventDispatchChain.

Construct an event dispatch chain for this target.

public boolean

Returns:

returns true if the cancel was successful
cancel
()

Implements javafx.concurrent.Worker.cancel.

Cancels any currently running Task, if any.

pack-priv void
cancelFromReadyState()

This is used by ScheduledService to cancel a Service that is in the READY state.

protected void
cancelled()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the CANCELLED state.

pack-priv void
protected abstract Task<V>

Returns:

the Task to execute
createTask
()

Invoked after the Service is started on the JavaFX Application Thread.

public final ReadOnlyObjectProperty<Throwable>
exceptionProperty()

Implements javafx.concurrent.Worker.exceptionProperty.

Gets the ReadOnlyObjectProperty representing any exception which occurred.

protected void
executeTask(final Task<V>
a non-null task to execute
task
)

Uses the executor defined on this Service to execute the given task.

public final ObjectProperty<Executor>
protected void
failed()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the FAILED state.

protected final void
fireEvent(Event
the event to fire
event
)

Fires the specified event.

private EventHelper
public final Throwable
getException()

Implements javafx.concurrent.Worker.getException.

Indicates the exception which occurred while the Worker was running, if any.

public final Executor
public final String
getMessage()

Implements javafx.concurrent.Worker.getMessage.

Gets a message associated with the current state of this Worker.

public final EventHandler<WorkerStateEvent>

Returns:

the onCancelled event handler, if any
getOnCancelled
()

The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.

public final EventHandler<WorkerStateEvent>

Returns:

the onFailed event handler, if any
getOnFailed
()

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

public final EventHandler<WorkerStateEvent>

Returns:

the onReady event handler, if any
getOnReady
()

The onReady event handler is called whenever the Task state transitions to the READY state.

public final EventHandler<WorkerStateEvent>

Returns:

the onRunning event handler, if any
getOnRunning
()

The onRunning event handler is called whenever the Task state transitions to the RUNNING state.

public final EventHandler<WorkerStateEvent>

Returns:

the onScheduled event handler, if any
getOnScheduled
()

The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.

public final EventHandler<WorkerStateEvent>

Returns:

the onSucceeded event handler, if any
getOnSucceeded
()

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

public final double
getProgress()

Implements javafx.concurrent.Worker.getProgress.

Indicates the current progress of this Worker in terms of percent complete.

public final Worker.State
getState()

Implements javafx.concurrent.Worker.getState.

Specifies the current state of this Worker.

public final String
getTitle()

Implements javafx.concurrent.Worker.getTitle.

An optional title that should be associated with this Worker.

public final double
getTotalWork()

Implements javafx.concurrent.Worker.getTotalWork.

Indicates a maximum value for the workDoneProperty property.

public final V
getValue()

Implements javafx.concurrent.Worker.getValue.

Specifies the value, or result, of this Worker.

public final double
getWorkDone()

Implements javafx.concurrent.Worker.getWorkDone.

Indicates the current amount of work that has been completed.

pack-priv boolean
public final boolean
isRunning()

Implements javafx.concurrent.Worker.isRunning.

True if the state is either SCHEDULED or RUNNING.

public final ReadOnlyStringProperty
messageProperty()

Implements javafx.concurrent.Worker.messageProperty.

Gets the ReadOnlyStringProperty representing the message.

public final ObjectProperty<EventHandler<WorkerStateEvent>>

Returns:

the onCancelled event handler property
onCancelledProperty
()

The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.

public final ObjectProperty<EventHandler<WorkerStateEvent>>

Returns:

the onFailed event handler property
onFailedProperty
()

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

public final ObjectProperty<EventHandler<WorkerStateEvent>>

Returns:

the onReady event handler property
onReadyProperty
()

The onReady event handler is called whenever the Task state transitions to the READY state.

public final ObjectProperty<EventHandler<WorkerStateEvent>>

Returns:

the onRunning event handler property
onRunningProperty
()

The onRunning event handler is called whenever the Task state transitions to the RUNNING state.

public final ObjectProperty<EventHandler<WorkerStateEvent>>

Returns:

the onScheduled event handler property
onScheduledProperty
()

The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.

public final ObjectProperty<EventHandler<WorkerStateEvent>>

Returns:

the onSucceeded event handler property
onSucceededProperty
()

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

public final ReadOnlyDoubleProperty
progressProperty()

Implements javafx.concurrent.Worker.progressProperty.

Gets the ReadOnlyDoubleProperty representing the progress.

protected void
ready()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the READY state.

public final <T extends Event> void
removeEventFilter(final EventType<T> eventType, final EventHandler<? super T> eventFilter)

Overrides default javafx.event.EventTarget.removeEventFilter.

Unregisters a previously registered event filter from this target.

public final <T extends Event> void
removeEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)

Overrides default javafx.event.EventTarget.removeEventHandler.

Unregisters a previously registered event handler from this target.

public void
reset()

Resets the Service.

public void
restart()

Cancels any currently running Task, if any, and restarts this Service.

pack-priv void
protected void
running()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the RUNNING state.

public final ReadOnlyBooleanProperty
runningProperty()

Implements javafx.concurrent.Worker.runningProperty.

Gets the ReadOnlyBooleanProperty representing whether the Worker is running.

protected void
scheduled()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SCHEDULED state.

protected final <
the specific event class of the handler
T extends Event
>
void
setEventHandler(final EventType<T>
the event type to associate with the given eventHandler
eventType
,
final EventHandler<? super T>
the handler to register, or null to unregister
eventHandler
)

Sets the handler to use for this event type.

public final void
public final void
setOnCancelled(EventHandler<WorkerStateEvent>
the event handler, can be null to clear it
value
)

The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.

public final void
setOnFailed(EventHandler<WorkerStateEvent>
the event handler, can be null to clear it
value
)

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

public final void
setOnReady(EventHandler<WorkerStateEvent>
the event handler, can be null to clear it
value
)

The onReady event handler is called whenever the Task state transitions to the READY state.

public final void
setOnRunning(EventHandler<WorkerStateEvent>
the event handler, can be null to clear it
value
)

The onRunning event handler is called whenever the Task state transitions to the RUNNING state.

public final void
setOnScheduled(EventHandler<WorkerStateEvent>
the event handler, can be null to clear it
value
)

The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.

public final void
setOnSucceeded(EventHandler<WorkerStateEvent>
the event handler, can be null to clear it
value
)

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

public void
start()

Starts this Service.

public final ReadOnlyObjectProperty<Worker.State>
stateProperty()

Implements javafx.concurrent.Worker.stateProperty.

Gets the ReadOnlyObjectProperty representing the current state.

protected void
succeeded()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SUCCEEDED state.

public final ReadOnlyStringProperty
titleProperty()

Implements javafx.concurrent.Worker.titleProperty.

Gets the ReadOnlyStringProperty representing the title.

public final ReadOnlyDoubleProperty
totalWorkProperty()

Implements javafx.concurrent.Worker.totalWorkProperty.

Gets the ReadOnlyDoubleProperty representing the maximum amount of work that needs to be done.

public final ReadOnlyObjectProperty<V>
valueProperty()

Implements javafx.concurrent.Worker.valueProperty.

Gets the ReadOnlyObjectProperty representing the value.

public final ReadOnlyDoubleProperty
workDoneProperty()

Implements javafx.concurrent.Worker.workDoneProperty.

Gets the ReadOnlyDoubleProperty representing the current progress.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

eventHelperback to summary
private EventHelper eventHelper
exceptionback to summary
private final ObjectProperty<Throwable> exception
EXECUTORback to summary
private static final ThreadPoolExecutor EXECUTOR
executorback to summary
private final ObjectProperty<Executor> executor

The executor to use for running this Service. If no executor is specified, then a new daemon thread will be created and used for running the Service using some default executor.

IO_QUEUEback to summary
private static final BlockingQueue<Runnable> IO_QUEUE

Because the ThreadPoolExecutor works completely backwards from what we want (ie: it doesn't increase thread count beyond the core pool size unless the queue is full), our queue has to be smart in that it will REJECT an item in the queue unless the thread size in the EXECUTOR is > 32, in which case we will queue up.

LOGback to summary
private static final PlatformLogger LOG

Logger used in the case of some uncaught exceptions

messageback to summary
private final StringProperty message
progressback to summary
private final DoubleProperty progress
runningback to summary
private final BooleanProperty running
startedOnceback to summary
private volatile boolean startedOnce

This boolean is set to true once the Service has been initially started. You can initialize the Service from any thread, and you can initially start it from any thread. But any subsequent usage of the service's methods must occur on the FX application thread.

stateback to summary
private final ObjectProperty<Worker.State> state
taskback to summary
private Task<V> task

A reference to the last task that was executed. I need this reference so that in the restart method I can cancel the currently running task, and so the cancel method can cancel the currently running task.

THREAD_FACTORYback to summary
private static final ThreadFactory THREAD_FACTORY
THREAD_GROUPback to summary
private static final ThreadGroup THREAD_GROUP
THREAD_POOL_SIZEback to summary
private static final int THREAD_POOL_SIZE
THREAD_TIME_OUTback to summary
private static final long THREAD_TIME_OUT
titleback to summary
private final StringProperty title
totalWorkToBeDoneback to summary
private final DoubleProperty totalWorkToBeDone
UNCAUGHT_HANDLERback to summary
private static final Thread.UncaughtExceptionHandler UNCAUGHT_HANDLER
valueback to summary
private final ObjectProperty<V> value
workDoneback to summary
private final DoubleProperty workDone

Constructor Detail

Serviceback to summary
protected Service()

Create a new Service.

Method Detail

addEventFilterback to summary
public final <T extends Event> void addEventFilter(final EventType<T> eventType, final EventHandler<? super T> eventFilter)

Overrides default javafx.event.EventTarget.addEventFilter.

Doc from javafx.event.EventTarget.addEventFilter.

Registers an event filter for this target.

The filter is called when the target receives an Event of the specified type during the capturing phase of event delivery.

Annotations
@Override
Since
JavaFX 2.1
addEventHandlerback to summary
public final <T extends Event> void addEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)

Overrides default javafx.event.EventTarget.addEventHandler.

Doc from javafx.event.EventTarget.addEventHandler.

Registers an event handler for this target.

The handler is called when the target receives an Event of the specified type during the bubbling phase of event delivery.

Annotations
@Override
Since
JavaFX 2.1
buildEventDispatchChainback to summary
public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)

Implements javafx.event.EventTarget.buildEventDispatchChain.

Doc from javafx.event.EventTarget.buildEventDispatchChain.

Construct an event dispatch chain for this target. The event dispatch chain contains event dispatchers which might be interested in processing of events targeted at this EventTarget. This event target is not automatically added to the chain, so if it wants to process events, it needs to add an EventDispatcher for itself to the chain.

In the case the event target is part of some hierarchy, the chain for it is usually built from event dispatchers collected from the root of the hierarchy to the event target.

The event dispatch chain is constructed by modifications to the provided initial event dispatch chain. The returned chain should have the initial chain at its end so the dispatchers should be prepended to the initial chain.

The caller shouldn't assume that the initial chain remains unchanged nor that the returned value will reference a different chain.

Annotations
@Override
cancelback to summary
public boolean cancel()

Implements javafx.concurrent.Worker.cancel.

Cancels any currently running Task, if any. The state will be set to CANCELLED.

Returns:boolean

returns true if the cancel was successful

Annotations
@Override
cancelFromReadyStateback to summary
pack-priv void cancelFromReadyState()

This is used by ScheduledService to cancel a Service that is in the READY state. The problem is that a ScheduledService will iterate from SUCCEEDED to READY, and then call start() to transition from READY to SCHEDULED and kick off a new iteration. However, if from the SUCCEEDED event handler a developer calls "cancel" to stop a ScheduledService, we have a problem, since the Service specification does not allow to transition from a terminal state (SUCCEEDED) to another terminal state (CANCELLED), but this is clearly what we need to do. So what this method will do is allow us to transition from the READY state to the CANCELLED state, by transitioning through SCHEDULED

cancelledback to summary
protected void cancelled()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the CANCELLED state. This method is invoked after the Service has been fully transitioned to the new state.

Since
JavaFX 2.1
checkThreadback to summary
pack-priv void checkThread()
createTaskback to summary
protected abstract Task<V> createTask()

Invoked after the Service is started on the JavaFX Application Thread. Implementations should save off any state into final variables prior to creating the Task, since accessing properties defined on the Service within the background thread code of the Task will result in exceptions. For example:


    protected Task createTask() {
        final String url = myService.getUrl();
        return new Task<String>() {
            protected String call() {
                URL u = new URL("http://www.oracle.com");
                BufferedReader in = new BufferedReader(
                        new InputStreamReader(u.openStream()));
                String result = in.readLine();
                in.close();
                return result;
            }
        }
    }

If the Task is a pre-defined class (as opposed to being an anonymous class), and if it followed the recommended best-practice, then there is no need to save off state prior to constructing the Task since its state is completely provided in its constructor.

protected Task createTask() {
        // This is safe because getUrl is called on the FX Application
        // Thread and the FirstLineReaderTasks stores it as an
        // immutable property
        return new FirstLineReaderTask(myService.getUrl());
    }
Returns:Task<V>

the Task to execute

exceptionPropertyback to summary
public final ReadOnlyObjectProperty<Throwable> exceptionProperty()

Implements javafx.concurrent.Worker.exceptionProperty.

Doc from javafx.concurrent.Worker.exceptionProperty.

Gets the ReadOnlyObjectProperty representing any exception which occurred.

Annotations
@Override
executeTaskback to summary
protected void executeTask(final Task<V> task)

Uses the executor defined on this Service to execute the given task. If the executor is null, then a default executor is used which will create a new daemon thread on which to execute this task.

This method is intended only to be called by the Service implementation.

Parameters
task:Task<V>

a non-null task to execute

Since
JavaFX 2.1
executorPropertyback to summary
public final ObjectProperty<Executor> executorProperty()
failedback to summary
protected void failed()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the FAILED state. This method is invoked after the Service has been fully transitioned to the new state.

Since
JavaFX 2.1
fireEventback to summary
protected final void fireEvent(Event event)

Fires the specified event. Any event filter encountered will be notified and can consume the event. If not consumed by the filters, the event handlers on this task are notified. If these don't consume the event either, then all event handlers are called and can consume the event.

This method must be called on the FX user thread.

Parameters
event:Event

the event to fire

Since
JavaFX 2.1
getEventHelperback to summary
private EventHelper getEventHelper()
getExceptionback to summary
public final Throwable getException()

Implements javafx.concurrent.Worker.getException.

Doc from javafx.concurrent.Worker.getException.

Indicates the exception which occurred while the Worker was running, if any. If this property value is null, there is no known exception, even if the status is FAILED. If this property is not null, it will most likely contain an exception that describes the cause of failure.

Annotations
@Override
getExecutorback to summary
public final Executor getExecutor()
getMessageback to summary
public final String getMessage()

Implements javafx.concurrent.Worker.getMessage.

Doc from javafx.concurrent.Worker.getMessage.

Gets a message associated with the current state of this Worker. This may be something such as "Processing image 1 of 3", for example.

Annotations
@Override
getOnCancelledback to summary
public final EventHandler<WorkerStateEvent> getOnCancelled()

The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.

Returns:EventHandler<WorkerStateEvent>

the onCancelled event handler, if any

Since
JavaFX 2.1
getOnFailedback to summary
public final EventHandler<WorkerStateEvent> getOnFailed()

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

Returns:EventHandler<WorkerStateEvent>

the onFailed event handler, if any

Since
JavaFX 2.1
getOnReadyback to summary
public final EventHandler<WorkerStateEvent> getOnReady()

The onReady event handler is called whenever the Task state transitions to the READY state.

Returns:EventHandler<WorkerStateEvent>

the onReady event handler, if any

Since
JavaFX 2.1
getOnRunningback to summary
public final EventHandler<WorkerStateEvent> getOnRunning()

The onRunning event handler is called whenever the Task state transitions to the RUNNING state.

Returns:EventHandler<WorkerStateEvent>

the onRunning event handler, if any

Since
JavaFX 2.1
getOnScheduledback to summary
public final EventHandler<WorkerStateEvent> getOnScheduled()

The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.

Returns:EventHandler<WorkerStateEvent>

the onScheduled event handler, if any

Since
JavaFX 2.1
getOnSucceededback to summary
public final EventHandler<WorkerStateEvent> getOnSucceeded()

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

Returns:EventHandler<WorkerStateEvent>

the onSucceeded event handler, if any

Since
JavaFX 2.1
getProgressback to summary
public final double getProgress()

Implements javafx.concurrent.Worker.getProgress.

Doc from javafx.concurrent.Worker.getProgress.

Indicates the current progress of this Worker in terms of percent complete. A value between zero and one indicates progress toward completion. A value of -1 means that the current progress cannot be determined (that is, it is indeterminate). This property may or may not change from its default value of -1 depending on the specific Worker implementation.

Annotations
@Override
getStateback to summary
public final Worker.State getState()

Implements javafx.concurrent.Worker.getState.

Doc from javafx.concurrent.Worker.getState.

Specifies the current state of this Worker. The initial value is State.READY. A Task may be restarted, in which case it will progress from one of these end states (SUCCEEDED, CANCELLED, or FAILED) back to READY and then immediately to SCHEDULED and RUNNING. These state transitions may occur immediately one after the other, but will always occur in the prescribed order.

Annotations
@Override
getTitleback to summary
public final String getTitle()

Implements javafx.concurrent.Worker.getTitle.

Doc from javafx.concurrent.Worker.getTitle.

An optional title that should be associated with this Worker. This may be something such as "Modifying Images".

Annotations
@Override
getTotalWorkback to summary
public final double getTotalWork()

Implements javafx.concurrent.Worker.getTotalWork.

Doc from javafx.concurrent.Worker.getTotalWork.

Indicates a maximum value for the workDoneProperty property. The totalWork will either be -1 (indicating that the amount of work to do is indeterminate), or it will be a non-zero value less than or equal to Double.MAX_VALUE.

Annotations
@Override
getValueback to summary
public final V getValue()

Implements javafx.concurrent.Worker.getValue.

Doc from javafx.concurrent.Worker.getValue.

Specifies the value, or result, of this Worker. This is set upon entering the SUCCEEDED state, and cleared (set to null) if the Worker is reinitialized (that is, if the Worker is a reusable Worker and is reset or restarted).

Annotations
@Override
getWorkDoneback to summary
public final double getWorkDone()

Implements javafx.concurrent.Worker.getWorkDone.

Doc from javafx.concurrent.Worker.getWorkDone.

Indicates the current amount of work that has been completed. Zero or a positive value indicate progress toward completion. This variables value may or may not change from its default value depending on the specific Worker implementation. A value of -1 means that the current amount of work done cannot be determined (ie: it is indeterminate). The value of this property is always less than or equal to totalWork.

Annotations
@Override
isFxApplicationThreadback to summary
pack-priv boolean isFxApplicationThread()
isRunningback to summary
public final boolean isRunning()

Implements javafx.concurrent.Worker.isRunning.

Doc from javafx.concurrent.Worker.isRunning.

True if the state is either SCHEDULED or RUNNING. When binding a Worker to a javafx.scene.control.ProgressIndicator, you will typically bind the visibility of the ProgressIndicator to the Worker's running property, and the progress of the ProgressIndicator to the Worker's progress property.

Annotations
@Override
messagePropertyback to summary
public final ReadOnlyStringProperty messageProperty()

Implements javafx.concurrent.Worker.messageProperty.

Doc from javafx.concurrent.Worker.messageProperty.

Gets the ReadOnlyStringProperty representing the message.

Annotations
@Override
onCancelledPropertyback to summary
public final ObjectProperty<EventHandler<WorkerStateEvent>> onCancelledProperty()

The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.

Returns:ObjectProperty<EventHandler<WorkerStateEvent>>

the onCancelled event handler property

Since
JavaFX 2.1
onFailedPropertyback to summary
public final ObjectProperty<EventHandler<WorkerStateEvent>> onFailedProperty()

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

Returns:ObjectProperty<EventHandler<WorkerStateEvent>>

the onFailed event handler property

Since
JavaFX 2.1
onReadyPropertyback to summary
public final ObjectProperty<EventHandler<WorkerStateEvent>> onReadyProperty()

The onReady event handler is called whenever the Task state transitions to the READY state.

Returns:ObjectProperty<EventHandler<WorkerStateEvent>>

the onReady event handler property

Since
JavaFX 2.1
onRunningPropertyback to summary
public final ObjectProperty<EventHandler<WorkerStateEvent>> onRunningProperty()

The onRunning event handler is called whenever the Task state transitions to the RUNNING state.

Returns:ObjectProperty<EventHandler<WorkerStateEvent>>

the onRunning event handler property

Since
JavaFX 2.1
onScheduledPropertyback to summary
public final ObjectProperty<EventHandler<WorkerStateEvent>> onScheduledProperty()

The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.

Returns:ObjectProperty<EventHandler<WorkerStateEvent>>

the onScheduled event handler property

Since
JavaFX 2.1
onSucceededPropertyback to summary
public final ObjectProperty<EventHandler<WorkerStateEvent>> onSucceededProperty()

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

Returns:ObjectProperty<EventHandler<WorkerStateEvent>>

the onSucceeded event handler property

Since
JavaFX 2.1
progressPropertyback to summary
public final ReadOnlyDoubleProperty progressProperty()

Implements javafx.concurrent.Worker.progressProperty.

Doc from javafx.concurrent.Worker.progressProperty.

Gets the ReadOnlyDoubleProperty representing the progress.

Annotations
@Override
readyback to summary
protected void ready()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the READY state. This method is invoked after the Service has been fully transitioned to the new state.

Since
JavaFX 2.1
removeEventFilterback to summary
public final <T extends Event> void removeEventFilter(final EventType<T> eventType, final EventHandler<? super T> eventFilter)

Overrides default javafx.event.EventTarget.removeEventFilter.

Doc from javafx.event.EventTarget.removeEventFilter.

Unregisters a previously registered event filter from this target.

Since it is possible to register a single EventHandler instance for different event types, the caller needs to specify the event type from which the filter should be unregistered.

Annotations
@Override
Since
JavaFX 2.1
removeEventHandlerback to summary
public final <T extends Event> void removeEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)

Overrides default javafx.event.EventTarget.removeEventHandler.

Doc from javafx.event.EventTarget.removeEventHandler.

Unregisters a previously registered event handler from this target.

Since it is possible to register a single EventHandler instance for different event types, the caller needs to specify the event type from which the handler should be unregistered.

Annotations
@Override
Since
JavaFX 2.1
resetback to summary
public void reset()

Resets the Service. May only be called while in one of the finish states, that is, SUCCEEDED, FAILED, or CANCELLED, or when READY. This method should only be called on the FX application thread.

restartback to summary
public void restart()

Cancels any currently running Task, if any, and restarts this Service. The state will be reset to READY prior to execution. This method should only be called on the FX application thread.

runLaterback to summary
pack-priv void runLater(Runnable r)
runningback to summary
protected void running()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the RUNNING state. This method is invoked after the Service has been fully transitioned to the new state.

Since
JavaFX 2.1
runningPropertyback to summary
public final ReadOnlyBooleanProperty runningProperty()

Implements javafx.concurrent.Worker.runningProperty.

Doc from javafx.concurrent.Worker.runningProperty.

Gets the ReadOnlyBooleanProperty representing whether the Worker is running.

Annotations
@Override
scheduledback to summary
protected void scheduled()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SCHEDULED state. This method is invoked after the Service has been fully transitioned to the new state.

Since
JavaFX 2.1
setEventHandlerback to summary
protected final <T extends Event> void setEventHandler(final EventType<T> eventType, final EventHandler<? super T> eventHandler)

Sets the handler to use for this event type. There can only be one such handler specified at a time. This handler is guaranteed to be called first. This is used for registering the user-defined onFoo event handlers.

Parameters
<T>
the specific event class of the handler
eventType:EventType<T>

the event type to associate with the given eventHandler

eventHandler:EventHandler<? super T>

the handler to register, or null to unregister

Exceptions
NullPointerException:
if the event type is null
Since
JavaFX 2.1
setExecutorback to summary
public final void setExecutor(Executor value)
setOnCancelledback to summary
public final void setOnCancelled(EventHandler<WorkerStateEvent> value)

The onCancelled event handler is called whenever the Task state transitions to the CANCELLED state.

Parameters
value:EventHandler<WorkerStateEvent>

the event handler, can be null to clear it

Since
JavaFX 2.1
setOnFailedback to summary
public final void setOnFailed(EventHandler<WorkerStateEvent> value)

The onFailed event handler is called whenever the Task state transitions to the FAILED state.

Parameters
value:EventHandler<WorkerStateEvent>

the event handler, can be null to clear it

Since
JavaFX 2.1
setOnReadyback to summary
public final void setOnReady(EventHandler<WorkerStateEvent> value)

The onReady event handler is called whenever the Task state transitions to the READY state.

Parameters
value:EventHandler<WorkerStateEvent>

the event handler, can be null to clear it

Since
JavaFX 2.1
setOnRunningback to summary
public final void setOnRunning(EventHandler<WorkerStateEvent> value)

The onRunning event handler is called whenever the Task state transitions to the RUNNING state.

Parameters
value:EventHandler<WorkerStateEvent>

the event handler, can be null to clear it

Since
JavaFX 2.1
setOnScheduledback to summary
public final void setOnScheduled(EventHandler<WorkerStateEvent> value)

The onSchedule event handler is called whenever the Task state transitions to the SCHEDULED state.

Parameters
value:EventHandler<WorkerStateEvent>

the event handler, can be null to clear it

Since
JavaFX 2.1
setOnSucceededback to summary
public final void setOnSucceeded(EventHandler<WorkerStateEvent> value)

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

Parameters
value:EventHandler<WorkerStateEvent>

the event handler, can be null to clear it

Since
JavaFX 2.1
startback to summary
public void start()

Starts this Service. The Service must be in the READY state to succeed in this call. This method should only be called on the FX application thread.

statePropertyback to summary
public final ReadOnlyObjectProperty<Worker.State> stateProperty()

Implements javafx.concurrent.Worker.stateProperty.

Doc from javafx.concurrent.Worker.stateProperty.

Gets the ReadOnlyObjectProperty representing the current state.

Annotations
@Override
succeededback to summary
protected void succeeded()

A protected convenience method for subclasses, called whenever the state of the Service has transitioned to the SUCCEEDED state. This method is invoked after the Service has been fully transitioned to the new state.

Since
JavaFX 2.1
titlePropertyback to summary
public final ReadOnlyStringProperty titleProperty()

Implements javafx.concurrent.Worker.titleProperty.

Doc from javafx.concurrent.Worker.titleProperty.

Gets the ReadOnlyStringProperty representing the title.

Annotations
@Override
totalWorkPropertyback to summary
public final ReadOnlyDoubleProperty totalWorkProperty()

Implements javafx.concurrent.Worker.totalWorkProperty.

Doc from javafx.concurrent.Worker.totalWorkProperty.

Gets the ReadOnlyDoubleProperty representing the maximum amount of work that needs to be done. These "work units" have meaning to the Worker implementation, such as the number of bytes that need to be downloaded or the number of images to process or some other such metric.

Annotations
@Override
valuePropertyback to summary
public final ReadOnlyObjectProperty<V> valueProperty()

Implements javafx.concurrent.Worker.valueProperty.

Doc from javafx.concurrent.Worker.valueProperty.

Gets the ReadOnlyObjectProperty representing the value.

Annotations
@Override
workDonePropertyback to summary
public final ReadOnlyDoubleProperty workDoneProperty()

Implements javafx.concurrent.Worker.workDoneProperty.

Doc from javafx.concurrent.Worker.workDoneProperty.

Gets the ReadOnlyDoubleProperty representing the current progress.

Annotations
@Override