I'm working with a database in Java and have been writing multiple functions along the lines of
try {
//acquire resources
}
finally {
//release resources
}
I know that Java's try-with-resources is a decent way to deal with something like this, but I'm using Java 6. Is there a standard way to reduce code duplication? I'd love to have a clean way of writing multiple functions which have the same try/finally blocks for resource allocation, but whose body differs.
My current thought was to make the bodies of the function members of a class whose constructor acquires the resources. But, without RAII, it seems a bit messy still.