Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips February 2022
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 255 contents
https://aredko.blogspot.com/2021/11/the-final-days-of-finalizers-in-java.html
The final days of finalizers in Java (Page last updated November 2021, Added 2022-02-26, Author Andriy Redko, Publisher aredko). Tips:
- Using java.lang.ref.Cleaner is straightforward: get a Cleaner instance from Cleaner.create(); register a cleanup action.
- A simple java.lang.ref.Cleaner example to clean up resources (for some
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.
Jack Shirazi
Back to newsletter 255 contents
Last Updated: 2025-02-25
Copyright © 2000-2025 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips255.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us