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 |
|---|---|
| public static interface | AsynchronousFinalizer.
An interface to represent bodies of finalize methods. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private final LinkedList | |
| private final Thread |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(AsynchronousFinalizer.
represents the body of some finalize method; must not be null. jobAdd a job to be executed asynchronously. |
| public void |
| done | back to summary |
|---|---|
| private boolean done | |
| queue | back to summary |
|---|---|
| private final LinkedList<AsynchronousFinalizer. | |
| thread | back to summary |
|---|---|
| private final Thread thread | |
| AsynchronousFinalizer | back to summary |
|---|---|
| public AsynchronousFinalizer() | |
| add | back to summary |
|---|---|
| public void add(AsynchronousFinalizer. Add a job to be executed asynchronously. The run method of the given job is called exactly once. If it terminates abnormally by throwing any Throwable, that is ignored.
| |
| drain | back to summary |
|---|---|
| public void drain() throws InterruptedException | |
Runnable, except that the run method may throw any
Throwable (which is effectively ignored by
AsynchronousFinalizer.add, similar to any Throwables
raised by finalize being ignored).
| Modifier and Type | Method and Description |
|---|---|
| public void |
| run | back to summary |
|---|---|
| public void run() throws Throwable | |