< prev index next >

modules/javafx.graphics/src/main/java/javafx/concurrent/Service.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  37 import javafx.beans.property.SimpleDoubleProperty;
  38 import javafx.beans.property.SimpleObjectProperty;
  39 import javafx.beans.property.SimpleStringProperty;
  40 import javafx.beans.property.StringProperty;
  41 import javafx.beans.value.ChangeListener;
  42 import javafx.beans.value.ObservableValue;
  43 import javafx.event.Event;
  44 import javafx.event.EventDispatchChain;
  45 import javafx.event.EventHandler;
  46 import javafx.event.EventTarget;
  47 import javafx.event.EventType;
  48 import java.security.AccessController;
  49 import java.security.AccessControlContext;
  50 import java.security.PrivilegedAction;
  51 import java.util.concurrent.BlockingQueue;
  52 import java.util.concurrent.Executor;
  53 import java.util.concurrent.LinkedBlockingQueue;
  54 import java.util.concurrent.ThreadFactory;
  55 import java.util.concurrent.ThreadPoolExecutor;
  56 import java.util.concurrent.TimeUnit;
  57 import sun.util.logging.PlatformLogger;
  58 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_CANCELLED;
  59 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_FAILED;
  60 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_READY;
  61 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_RUNNING;
  62 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_SCHEDULED;
  63 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_SUCCEEDED;
  64 
  65 /**
  66  * <p>
  67  *     A Service is a non-visual component encapsulating the information required
  68  *     to perform some work on one or more background threads. As part of the
  69  *     JavaFX UI library, the Service knows about the JavaFX Application thread
  70  *     and is designed to relieve the application developer from the burden
  71  *     of managing multithreaded code that interacts with the user interface. As
  72  *     such, all of the methods and state on the Service are intended to be
  73  *     invoked exclusively from the JavaFX Application thread. The only exception
  74  *     to this, is when initially configuring a Service, which may safely be done
  75  *     from any thread, and initially starting a Service, which may also safely
  76  *     be done from any thread. However, once the Service has been initialized and
  77  *     started, it may only thereafter be used from the FX thread.


   1 /*
   2  * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  37 import javafx.beans.property.SimpleDoubleProperty;
  38 import javafx.beans.property.SimpleObjectProperty;
  39 import javafx.beans.property.SimpleStringProperty;
  40 import javafx.beans.property.StringProperty;
  41 import javafx.beans.value.ChangeListener;
  42 import javafx.beans.value.ObservableValue;
  43 import javafx.event.Event;
  44 import javafx.event.EventDispatchChain;
  45 import javafx.event.EventHandler;
  46 import javafx.event.EventTarget;
  47 import javafx.event.EventType;
  48 import java.security.AccessController;
  49 import java.security.AccessControlContext;
  50 import java.security.PrivilegedAction;
  51 import java.util.concurrent.BlockingQueue;
  52 import java.util.concurrent.Executor;
  53 import java.util.concurrent.LinkedBlockingQueue;
  54 import java.util.concurrent.ThreadFactory;
  55 import java.util.concurrent.ThreadPoolExecutor;
  56 import java.util.concurrent.TimeUnit;
  57 import com.sun.javafx.logging.PlatformLogger;
  58 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_CANCELLED;
  59 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_FAILED;
  60 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_READY;
  61 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_RUNNING;
  62 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_SCHEDULED;
  63 import static javafx.concurrent.WorkerStateEvent.WORKER_STATE_SUCCEEDED;
  64 
  65 /**
  66  * <p>
  67  *     A Service is a non-visual component encapsulating the information required
  68  *     to perform some work on one or more background threads. As part of the
  69  *     JavaFX UI library, the Service knows about the JavaFX Application thread
  70  *     and is designed to relieve the application developer from the burden
  71  *     of managing multithreaded code that interacts with the user interface. As
  72  *     such, all of the methods and state on the Service are intended to be
  73  *     invoked exclusively from the JavaFX Application thread. The only exception
  74  *     to this, is when initially configuring a Service, which may safely be done
  75  *     from any thread, and initially starting a Service, which may also safely
  76  *     be done from any thread. However, once the Service has been initialized and
  77  *     started, it may only thereafter be used from the FX thread.


< prev index next >