Releasing Resources
When tasks process, they use resources such as files, database
connections, or queue connection factories. When processing is completed
or during errors, before the task returns control to the Services Framework,
it is required to release any resources it used. Releasing resources
ensures no memory leaks and the JVM (Java™ Virtual
Machine) runs cleanly. An exception to releasing resources is to not
have the custom task perform a database close on the connection passed
to it. For example, the Java code
must not perform the following:
connect.close(); // Close Database connection called connectThe Base Task requires the task to implement a releaseResources() method.
public void releaseResources();When the task finishes processing, it should always call the releaseResources() method before returning control to the Services Framework. The Services Framework also calls the releaseResources() method after processing, which prevents custom tasks from leaving resources open.
Example
If a task writes to a file and a WebSphere® MQ queue, it is recommended for the releaseResources() method to be used. This ensures
all file and MQ resources are cleaned up. A code example is shown
here:
public void releaseResources()
{
if (fileOutputStream != null) {
fileOutputStream.close();
fileOutputStream = null;
}
if (mqSession != null) {
mqSession.close();
mqSession = null;
}
if (mqConnection != null) {
mqConnection.close();
mqConnection = null;
}
}Refer to the Javadoc information for additional information about methods and signatures.