Java Reference
In-Depth Information
the
Executor
. The
reset()
method can only be called when the
Service<V>
's state is not
Worker.State.SCHEDULED
or
Worker.State.RUNNING
. It simply unbinds the nine
Service<V>
properties from that of the underlying
Task
and
resets their values to fresh startup values:
Worker.State.READY
for the
state
property, and
null
or
""
or
false
or
-1
for the other properties. The
restart()
method simply cancels the currently executing
Task
, if any, and then does a
reset()
followed by a
start()
. The
cancel()
method will cancel the currently executing
Task
, if any; otherwise it will
transition the
Service<V>
to the
Worker.State.CANCELLED
state.
Listing 7-10 illustrates using an instance of an anonymous subclass of the
Service<V>
abstract class to execute
Task
s repeatedly in its own
Executor
.
Listing 7-10.
ServiceExample.java
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.concurrent.Worker;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.concurrent.atomic.AtomicBoolean;
public class ServiceExample extends Application {
private Model model;
private View view;
public static void main(String[] args) {
launch(args);
}
public ServiceExample() {
model = new Model();
}
@Override
public void start(Stage stage) throws Exception {
view = new View(model);
hookupEvents();
Search WWH ::
Custom Search