|
|
|
obj
) instead of implementing a finalize() method would be similar to Cleaner cleaner = Cleaner.create(); Cleaner.Cleanable cleanable = cleaner.register(obj, cleanupRunnableWhenObjGCed)
and if you want to execute the clean up early, you can execute cleanable.clean()
(which would execute the cleanupRunnableWhenObjGCed
runnable immediately. The runnable is never executed more than once even including GCs"