public final class RecursionSafeCaller extends Object implements Caller
Caller
implementation that implements immediate calling, and provides a fallback to
avoid blowing up the stack when operations are recursively called.
This implementation maintains a thread-local storage that gives a rough estimate of how deep a
given stack is.Constructor and Description |
---|
RecursionSafeCaller(ExecutorService executorService,
Caller caller) |
RecursionSafeCaller(ExecutorService executorService,
Caller caller,
long maxRecursionDepth) |
Modifier and Type | Method and Description |
---|---|
void |
execute(Runnable runnable)
Execute the given action.
|
void |
referenceLeaked(Object reference,
StackTraceElement[] stack)
Indicate that a Managed reference has been leaked.
|
public RecursionSafeCaller(ExecutorService executorService, Caller caller, long maxRecursionDepth)
public RecursionSafeCaller(ExecutorService executorService, Caller caller)
public void referenceLeaked(Object reference, StackTraceElement[] stack)
Caller
This is usually called by end-user code that never releases a managed reference, like this:
public static class Example {
private final Async async;
private final Managed<Database> database;
public Example(final Async async, final Managed<Database> database) {
this.async = async;
this.database = database;
}
public Stage<Void> doSomething() {
return database.doto(database -> {
Completable<Void> stage = async.completable();
return stage;
});
}
}
This leaves the managed database in an open state since its reference count will never go back to zero. When the stage and the corresponding borrowed is garbage collected, it will be reported here.
referenceLeaked
in interface Caller
reference
- the reference that was leakedstack
- the stacktrace for where it was leaked, can be null
if the information is
unavailableCopyright © 2017. All rights reserved.