|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectparatask.runtime.EventLoop
public class EventLoop
Thread-specific event loop. Any user-defined thread that makes use of the ParaTask clauses
notify
, asyncCatch
, or notifyInterim
must make use of
this EventLoop
. This also includes the main thread (the thread that invokes the
application's main
method). This requirement is necessary because such threads
do not have an event loop of their own, yet the above ParaTask clauses involve event-based callbacks.
ParaTask threads (i.e. any code executed inside a ParaTask task), and Java's Event Dispatch Thread (EDT)
(i.e. any code executed inside handlers such actionPerformed
, etc.) must not use
this EventLoop
since they already have an event loop of their own. However, in order to
initialise these event loops, the programmer is required to call ParaTask.init()
at the
start of the main
method of their application.
Note that if any thread has nothing to compute, then that thread will terminate. In particular, this means that if
the main thread (the thread that executes the main
method) returns from the main
method, then essentially the
application ends: any other running threads will also be terminated. For example, if the the main thread uses a
notifyGUI
clause, then the EDT might not have a chance to execute the clause and the also the worker
threads themselves might not be able to complete the tasks since the application terminates when the main thread
terminates. To avoid this, programmers should invoke ParaTask.init()
early in the main
method, and then
invoke exec()
at the end of the main
method so that the application remains active.
Method Summary | |
---|---|
static int |
exec()
The calling thread enters the event loop. |
static void |
quit()
Stops the event loop for the calling thread. |
static boolean |
register()
Register a user-defined thread (or the main thread) with ParaTask. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean register()
main
thread) with ParaTask. See class
description above for more details. The thread should call this method before it
invokes any tasks with ParaTask clauses, and before it enters the event loop.
true
if this thread is not registered already, otherwise false
if already registered.
java.lang.UnsupportedOperationException
- If attempting to register a ParaTask thread or the EDTexec()
public static int exec()
quit()
method is called.
java.lang.UnsupportedOperationException
- If executed by a ParaTask thread or the EDTregister()
,
quit()
public static void quit()
java.lang.UnsupportedOperationException
- If executed by a ParaTask thread or the EDTexec()
,
register()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |