< prev index next >
modules/javafx.graphics/src/main/java/javafx/concurrent/Task.java
Print this page
*** 75,89 ****
--- 75,91 ----
* can also call it directly (by invoking the {@link javafx.concurrent.Task#run()} method)
* from another background thread. This allows for composition of work, or pass it to
* a new Thread constructed and executed manually. Finally, since you can
* manually create a new Thread, passing it a Runnable, it is possible to use
* the following idiom:
+ * </p>
* <pre><code>
* Thread th = new Thread(task);
* th.setDaemon(true);
* th.start();
* </code></pre>
+ * <p>
* Note that this code sets the daemon flag of the Thread to true. If you
* want a background thread to prevent the VM from existing after the last
* stage is closed, then you would want daemon to be false. However, if
* you want the background threads to simply terminate after all the
* stages are closed, then you must set daemon to true.
*** 441,451 ****
* <pre><code>
* Task<ObservableList<Rectangle>> task = new Task<ObservableList<Rectangle>>() {
* @Override protected ObservableList<Rectangle> call() throws Exception {
* updateMessage("Creating Rectangles");
* ObservableList<Rectangle> results = FXCollections.observableArrayList();
! * for (int i=0; i<100; i++) {
* if (isCancelled()) break;
* Rectangle r = new Rectangle(10, 10);
* r.setX(10 * i);
* results.add(r);
* updateProgress(i, 100);
--- 443,453 ----
* <pre><code>
* Task<ObservableList<Rectangle>> task = new Task<ObservableList<Rectangle>>() {
* @Override protected ObservableList<Rectangle> call() throws Exception {
* updateMessage("Creating Rectangles");
* ObservableList<Rectangle> results = FXCollections.observableArrayList();
! * for (int i=0; i<100; i++) {
* if (isCancelled()) break;
* Rectangle r = new Rectangle(10, 10);
* r.setX(10 * i);
* results.add(r);
* updateProgress(i, 100);
*** 521,542 ****
* result.</p>
*
* <pre><code>
* public class PartialResultsTask extends Task<ObservableList<Rectangle>> {
* // Uses Java 7 diamond operator
! * private ReadOnlyObjectWrapper<ObservableList<Rectangle>> partialResults =
! * new ReadOnlyObjectWrapper<>(this, "partialResults",
! * FXCollections.observableArrayList(new ArrayList<Rectangle>()));
*
! * public final ObservableList<Rectangle> getPartialResults() { return partialResults.get(); }
! * public final ReadOnlyObjectProperty<ObservableList<Rectangle>> partialResultsProperty() {
* return partialResults.getReadOnlyProperty();
* }
*
! * @Override protected ObservableList<Rectangle> call() throws Exception {
* updateMessage("Creating Rectangles...");
! * for (int i=0; i<100; i++) {
* if (isCancelled()) break;
* final Rectangle r = new Rectangle(10, 10);
* r.setX(10 * i);
* Platform.runLater(new Runnable() {
* @Override public void run() {
--- 523,544 ----
* result.</p>
*
* <pre><code>
* public class PartialResultsTask extends Task<ObservableList<Rectangle>> {
* // Uses Java 7 diamond operator
! * private ReadOnlyObjectWrapper<ObservableList<Rectangle>> partialResults =
! * new ReadOnlyObjectWrapper<>(this, "partialResults",
! * FXCollections.observableArrayList(new ArrayList<Rectangle>()));
*
! * public final ObservableList<Rectangle> getPartialResults() { return partialResults.get(); }
! * public final ReadOnlyObjectProperty<ObservableList<Rectangle>> partialResultsProperty() {
* return partialResults.getReadOnlyProperty();
* }
*
! * @Override protected ObservableList<Rectangle> call() throws Exception {
* updateMessage("Creating Rectangles...");
! * for (int i=0; i<100; i++) {
* if (isCancelled()) break;
* final Rectangle r = new Rectangle(10, 10);
* r.setX(10 * i);
* Platform.runLater(new Runnable() {
* @Override public void run() {
*** 561,571 ****
*
* <pre><code>
* final Group group = new Group();
* Task<Void> task = new Task<Void>() {
* @Override protected Void call() throws Exception {
! * for (int i=0; i<100; i++) {
* if (isCancelled()) break;
* final Rectangle r = new Rectangle(10, 10);
* r.setX(10 * i);
* Platform.runLater(new Runnable() {
* @Override public void run() {
--- 563,573 ----
*
* <pre><code>
* final Group group = new Group();
* Task<Void> task = new Task<Void>() {
* @Override protected Void call() throws Exception {
! * for (int i=0; i<100; i++) {
* if (isCancelled()) break;
* final Rectangle r = new Rectangle(10, 10);
* r.setX(10 * i);
* Platform.runLater(new Runnable() {
* @Override public void run() {
< prev index next >