On 01.12.2014, at 19:24, Marshall Schor <[email protected]> wrote:

> One approach would use the try/ finally form:
> 
>  controlVar = cas.startUimaIndexProtectedBlock();
>  try {
>    some code which modifies a FS (or maybe, multiple FSs
>  } finally {
>    controlVar.close();  // causes any "removes" to be now re-added to indices
>  }
> 
> A form like the above could use in Java 8 the simpler try-with-resources form:
>  try (controlVar = cas.startUimaIndexProtectedBlock()) {
>    some code which modifies a FS (or maybe, multiple FSs
>  }

For me, this smells a but like abusing try/catch, although I admit that
it also has some elegance.

Why not use an anonymous inner class like this:

cas.transaction(new Transaction<CAS>() {
  void perform(CAS cas) {
    // make modifications
  }
});

Afaik this works also in Java versions prior to 7. It's the kind of thing
one did before lambda arrived.

Cheers,

-- Richard

Reply via email to