Class Exit

  extended by com.caucho.util.Exit

public class Exit
extends java.lang.Object

The exit class is used to automatically clean state. For example, Resin JavaScript will close open files when the script exits. Here's a sample use:

   boolean isExit = addExit();
   try {
   } finally {
     if (isExit)

Objects register for the exit callback by calling addExit(listener, object).

Exits are intrinsically tied to a thread.

Method Summary
static boolean addExit()
          Starts a protection scope.
static void addExit(ExitListener listener, java.lang.Object object)
          Registers the object and listener.
static void exit()
          Calls all registered listeners.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static void addExit(ExitListener listener,
                           java.lang.Object object)
Registers the object and listener. The listener will be called when the thread exits the scope.

If there is no protection scope, i.e. addExit() hasn't been called, then this function does nothing.

listener - the exit handler
object - the object which needs cleanup


public static boolean addExit()
Starts a protection scope. Only the outermost scope is important, so protecting routines must check the return value to see if they are the outermost scope.

true if this is the outermost scope.


public static void exit()
Calls all registered listeners.