Tim Tripcony’s incinerate function elegantly batch recycles Domino Objects in Java

I recently was surfing through Stackoverflow and I hit a response from Tim Tripcony on this post: What is the best way to recycle Domino Objects in Java Beans

He published a small helper function to recycle an arbitrary number of Domino objects. It’s so simple, and so well written, that I thought it deserved a post of its own. Here it is in all its glory:

[sourcecode language=”java”]
private void incinerate(Object… dominoObjects) {
for (Object dominoObject : dominoObjects) {
if (null != dominoObject) {
if (dominoObject instanceof Base) {
try {
((Base)dominoObject).recycle();
} catch (NotesException recycleSucks) {
// optionally log exception
}
}
}
}
}
[/sourcecode]

And it’s used like this:
[sourcecode language=”java”]
Database wDb = null;
View wView = null;
Document wDoc = null;
try {
// your code here
} catch (NotesException ne) {
// do error handling
} finally {
incinerate(wDoc, wView, wDb);
}
[/sourcecode]

I find the function elegant in many ways; the function and the variables are clearly named, Tim uses variable-length argument lists (thats the Object… part with the ellipsis), the new for-each iteration, plus there is some humour. Thanks, Tim.

4 thoughts on “Tim Tripcony’s incinerate function elegantly batch recycles Domino Objects in Java”

  1. I have putted inside my JSFUtils Class, so if I use the core Notes Java classes, I can always call this method to recycle the objects.

  2. Instead of private void, why not public static void?
    Or you could just use the OpenNTF Domino API and stop worrying about recycling. It’s what Tim would have wanted .

Leave a Comment