objectdraw
Class ActiveObject

java.lang.Object
  extended byjava.lang.Thread
      extended byobjectdraw.ActiveObject
All Implemented Interfaces:
java.lang.Runnable

public class ActiveObject
extends java.lang.Thread

The class ActiveObject is used to define objects controlled by sequences of instructions that are executed independently of and simultaneously with other instructions in a program. The code that is to be executed independently should be placed in the body of a parameterless run method defined within a class definition that extends ActiveObject. When the start() method of an ActiveObject is invoked, the system will being to execute whatever code was placed in this run method.

ActiveObject is a simple extension of Java's native Thread class. ActiveObjects are automatically managed so that they are suspended and restarted when an applet is stopped and started. In addition, the sleep method provided in the Thread class is replaced with a similar pause method that does not require exception handling.

Version:
1.1.2 released July 2006

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ActiveObject()
          Construct an ActiveObject.
ActiveObject(java.lang.String name)
          Constructs an ActiveObject with a given name.
ActiveObject(java.lang.ThreadGroup group, java.lang.Runnable target, java.lang.String name)
          Construct a new ActiveObject with the specified name using the Runnable and ThreadGroup parameters to determine its behavior.
 
Method Summary
static void defer()
          Deprecated. use ActiveObject.yield() instead
static double getTime()
          Deprecated. use System.currentTimeMillis()
static void pause(double millis)
          Suspend the execution of this ActiveObject for at least the time period specified.
static void pause(long millis)
          Suspend the execution of this ActiveObject for at least the time period specified.
static void pause(long millis, int nano)
          Suspend the execution of this ActiveObject for at least the time period specified.
static void yield()
          Briefly suspend the execution of this ActiveObject code to see if any other ActiveObject or Thread is waiting to execute.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActiveObject

public ActiveObject()
Construct an ActiveObject.


ActiveObject

public ActiveObject(java.lang.String name)
Constructs an ActiveObject with a given name.

Parameters:
name - the name of the new ActiveObject.

ActiveObject

public ActiveObject(java.lang.ThreadGroup group,
                    java.lang.Runnable target,
                    java.lang.String name)
Construct a new ActiveObject with the specified name using the Runnable and ThreadGroup parameters to determine its behavior. If the target argument is not null, the run method of the target is executed when this thread is started. If the target argument is null, this thread's run method is executed when this thread is started. If group is null and there is a security manager, the group is determined by the security manager's getThreadGroup method. If group is null and there is not a security manager, or the security manager's getThreadGroup method returns null, the group is set to be the same ThreadGroup as the thread that is creating the new thread. If there is a security manager, its checkAccess method is called with the ThreadGroup as its argument. This may result in a SecurityException.

Parameters:
group - the thread group.
target - the object whose run method is called.
name - the name of the new ActiveObject.
Method Detail

defer

public static void defer()
Deprecated. use ActiveObject.yield() instead

Briefly suspend the execution of this ActiveObjects code to see if any other ActiveObject or Thread is waiting to execute. In addition, this method checks to see if the Controller has requested that this ActiveObject suspend or terminate its execution.


yield

public static void yield()
Briefly suspend the execution of this ActiveObject code to see if any other ActiveObject or Thread is waiting to execute. In addition, this method checks to see if the Controller has requested that this ActiveObject suspend or terminate its execution.


pause

public static void pause(long millis)
Suspend the execution of this ActiveObject for at least the time period specified.

Parameters:
millis - number of milliseconds to pause.

pause

public static void pause(double millis)
Suspend the execution of this ActiveObject for at least the time period specified.

Parameters:
millis - number of milliseconds to pause.

pause

public static void pause(long millis,
                         int nano)
Suspend the execution of this ActiveObject for at least the time period specified.

Parameters:
millis - number of milliseconds to pause.
nano - additional number of nanoseconds to pause.

getTime

public static double getTime()
Deprecated. use System.currentTimeMillis()

In earlier versions of objectdraw, this method was provided to determine the current time in milliseconds. It is now deprecated and throws an exception if invoked.

Returns:
nothing