In Java9, finalizers have been deprecated, instead cleaners have been introduced. What is the difference between the two?

In Java9 cleaners have been introduced and finalizers have been deprecated.
What is the purpose of introducing the cleaners and how and in what particular scenario we should be using them and not finalizers?

Solution:

The Deprecation of Finalizer in registers state the reason for the decision :-

Finalizers are inherently problematic and their use can lead to performance issues, deadlocks, hangs, and other problematic behavior.

Furthermore, the timing of finalization is unpredictable with no guarantee that a finalizer will be called. Classes whose instances hold non-heap resources should provide a method to enable explicit release of those resources, and they should also implement java.lang.AutoCloseable if appropriate.

The proposed solution as an alternative to using the Finalizers were the introduced Cleaners which would provide easy registration and cancellation of cleanup functions for objects.

The Cleaner
and PhantomReference provide more flexible and efficient ways to release resources when an object becomes unreachable.

Applications create a cleanup service for their own use and the service terminates when it is no longer in use.

Use: Once an object has become Phantom reachable the cleanup actions performed on the same are registered and managed by a Cleaner. Registering an object reference and corresponding cleaning action returns a Cleanable. The most efficient use is to explicitly invoke the clean method when the object is closed or no longer needed.

Note: Prior to Java9, a similar implementation of a Cleaner has been residing under sun.misc package as well.