Automatically terminating an application – Apple WebObjects 3.5 User Manual

Page 155

Advertising
background image

Automatically Terminating an Application

155

Automatically Terminating an Application

Unless an application is very carefully constructed, the longer it runs, the
more memory it consumes. As more memory is consumed, the server
machine’s performance begins to degrade. For this reason, you may find
that performance is greatly improved if you occasionally stop an application
instance and start a new one.

You can stop an application manually using the Monitor application
(described in the online document Serving WebObjects). Or you can include
code in the application to have it automatically terminate itself under
certain conditions. Either way, you might want to turn on application auto-
recovery in the Monitor application; that way, when the application dies, it
automatically restarts.

Idle time.

If no users are accessing the application, you might want to shut

it down until a user requests it. To do so, use WOApplication’s

setTimeOut:

method. This method shuts down the application after it has been idle
for a given number of seconds.

public Application() {

super();
this.setTimeOut(2*60*60); //shut down if idle 2 hours
...

}

Running time.

You can have an application terminate itself after a specific

amount of time has elapsed, regardless of whether it is idle or not using
the

terminateAfterTimeInterval:

method. For example, the following

application will terminate after 24 hours.

public Application() {

super();
this.terminateAfterTimeInterval(24*60*60);
...

}

After the specified time limit has elapsed,

terminateAfterTimeInterval:

immediately stops all current processing. If any sessions are active,
users may lose information.

Session count.

An application can also terminate if the number of active

sessions falls below a certain number. Use

setMinimumActiveSessionsCount:

to

set this number, and then send

refuseNewSessions:

to prevent the

application from creating more sessions. For example, if you want to
shut down your application after 24 hours but you want any current

Advertising