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:

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
                }
            }
        }
    }
}

And it’s used like this:

   Database wDb = null;
    View wView = null;
    Document wDoc = null;
    try {
// your code here
    } catch (NotesException ne) {
 // do error handling
    } finally {
        incinerate(wDoc, wView, wDb);
}

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s