/** * Execute given {@link Callable} <code>operation</code> on behalf of this PropertySet, i.e. binding this * PropertySet as {@link Context} resource to current Thread, and removing the binding after operation execution. * @param <V> Operation result type * @param operation Operation to execute * @return Operation result */ default <V> V execute(final Callable<V> operation) { return Context.get().executeThreadBound(CONTEXT_KEY, this, operation); }
public void threadScope() { Object resourceInstance = new String(); // tag::threadscope[] Context.get().executeThreadBound("resourceKey", resourceInstance, () -> { // do something // <1> }); Context.get().executeThreadBound("resourceKey", resourceInstance, () -> { // do something // <2> return null; }); // end::threadscope[] }