Web / Apache Commons Collections Interview questions
Explain the lifecycle of a ClosureUtils.chainedClosure() execution?
ClosureUtils.chainedClosure(closure1, closure2, ...) returns a single composite Closure that, when its execute(input) is called once, runs each wrapped closure in the order they were supplied, passing the same input object to every one of them in turn.
Because each sub-closure receives the same original input rather than a value returned by the previous step (Closure's execute() is void, so there's nothing to pass forward), the chain is really about running several independent side effects against one object in a fixed order - for example, logging an entry, then updating its state, then sending a notification - not about transforming data step by step the way a chained Transformer would.
If any closure in the chain throws a RuntimeException, execution stops immediately and the exception propagates to the caller - the remaining closures in the chain are never invoked, so a chain used for something like "log, then persist, then notify" needs to be ordered with that fail-fast behavior in mind, putting steps whose failure should block later steps earlier in the sequence.
More Related questions...