Game Development Reference
In-Depth Information
Java.lang.Object
> javafx.concurrent.Service
> javafx.concurrent. ScheduledService
Whereas Task (class) objects are used only one time, to accomplish a given task, a
service is ongoing, and a Service object and a ScheduledService (class) object can be
reused, that is, they are ready to perform their service at any time. This is more appro-
priate for game play processing, as game play continues for long periods of time, and
the assumption here is that the types of game logic processing involved will also need
to be calculated as time goes on during game play, and not just one single time, as with
the Task class (object).
The Worker Java construct is actually an interface , and the Task, Service, and
ScheduledService classes have been created for you, based on this Worker interface
(which is more than can be said for the EventHandler interface, which you have to
implement yourself!).
A Worker object performs processing, using a background thread, and can be either
reusable (such as in the Service class) or not reusable (such as in the Task class). Work-
er thread states are controlled by the Worker.State class (object) and contain the life
cycle stages for a Worker thread. These apply across the three primary classes in the
javafx.concurrent package, as they implement the Worker interface and its related nes-
ted classes. As mentioned in the previous chapter, a nested class is accessed via dot
notation, so the State class is thus nested inside the Worker interface (class ).
Because the states of a Worker thread are very important to understand before you use
it, I am going to detail them in the form of a table so that they are crystal clear to you
(see Table 4-3 ).
Table 4-3 . Worker Thread Life Cycle States, as Defined by the Worker.State Nested
Class for Use with a Worker Interface
Worker.State
Constant
Significance
READY
Worker object (thread) has been initialized (or reinitialized) and is ready
to be used.
SCHEDULED
Worker object (thread) has been scheduled for execution but is not cur-
rently running.
RUNNING
Worker object (thread) is currently running and is executing the Java pro-
gramming logic.
 
 
Search WWH ::




Custom Search