Skip to content

Instantly share code, notes, and snippets.

@kabutz
Created September 9, 2021 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kabutz/6cc4cb5a6518d3a09ffb76b61701005a to your computer and use it in GitHub Desktop.
Save kabutz/6cc4cb5a6518d3a09ffb76b61701005a to your computer and use it in GitHub Desktop.
// run with java -showversion CleanerDemo in Java 16 and 17 to see different results
import java.lang.ref.*;
public class CleanerDemo {
public static void main(String... args) throws InterruptedException {
Cleaner cleaner = Cleaner.create();
Cleaner.Cleanable cleanable = cleaner.register(new Object(),
() -> System.out.println("My cleaner thread priority is " +
Thread.currentThread().getPriority()));
System.gc();
Thread.sleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment