public final class AsynchronousFinalizer extends Object
Current JVMs seem not to be robust against long-running finalize methods, in that such long-running finalize methods may lead to OutOfMemoryErrors. This class mitigates the problem by asynchronously shifting the bodies of potentially long-running finalize methods into an extra thread. Classes that make use of this in their finalize methods are the proxies used in the intra-process JNI UNO bridge and the inter-process Java URP UNO bridge (where in both cases finalizers lead to synchronous UNO release calls).
Irrespective whether JVMs are getting more mature and should no longer have problems with long-running finalize methods, at least the JNI UNO bridge needs some way to stop finalization of proxies (to C++ objects) well before process exit, as provided by drain().
| Modifier and Type | Class and Description |
|---|---|
static interface |
AsynchronousFinalizer.Job
An interface to represent bodies of finalize methods.
|
| Constructor and Description |
|---|
AsynchronousFinalizer() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(AsynchronousFinalizer.Job job)
Add a job to be executed asynchronously.
|
void |
drain() |
public void add(AsynchronousFinalizer.Job job)
The run method of the given job is called exactly once. If it terminates abnormally by throwing any Throwable, that is ignored.
job - represents the body of some finalize method; must not be null.public void drain()
throws InterruptedException
InterruptedException