getTimeToLive(String, Locale): This method is available in java.util.ResourceBundle.Control class of Java.
Syntax:
long java.util.ResourceBundle.Control.getTimeToLive(String baseName, Locale locale)
This method takes two arguments. This method returns the time-to-live (TTL) value for resource bundles that are loaded under this ResourceBundle.Control.
Note:
1. Positive time-to-live values specify the number of milliseconds a bundle can remain in the cache without being validated against the source data from which it was constructed.
2. The value 0 indicates that a bundle must be validated each time it is retrieved from the cache.
3. TTL_NO_EXPIRATION_CONTROL specifies that loaded resource bundles are put in the cache with no expiration control.
Parameters: Two parameters are required for this method.
baseName: the base name of the resource bundle for which the expiration value is specified.
locale: the locale of the resource bundle for which the expiration value is specified.
Returns: the time (0 or a positive millisecond offset from the cached time) to get loaded bundles expired in the cache, TTL_NO_EXPIRATION_CONTROL to disable the expiration control, or TTL_DONT_CACHE to disable caching.
Throws:
NullPointerException - if baseName or locale is null
Approach 1: When no exception
Java
import java.util.Locale;import java.util.ResourceBundle;import java.util.ResourceBundle.Control;public class ResourceBundleControlgetTimeToLive {public static void main(String[] args) {ResourceBundle.Control reControl =ResourceBundle.Control.getControl(Control.FORMAT_DEFAULT);String baseName = "Hello";Locale locale = Locale.US;System.out.println(reControl.getTimeToLive(baseName, locale));}}
Output:
-2
Approach 2: NullPointerException
Java
import java.util.Locale;import java.util.ResourceBundle;import java.util.ResourceBundle.Control;public class ResourceBundleControlgetTimeToLive {public static void main(String[] args) {ResourceBundle.Control reControl =ResourceBundle.Control.getControl(Control.FORMAT_DEFAULT);String baseName = null;Locale locale = Locale.US;System.out.println(reControl.getTimeToLive(baseName, locale));}}
Output:
Exception in thread "main" java.lang.NullPointerException at java.base/java.util.ResourceBundle$Control.getTimeToLive(ResourceBundle.java:3304)
No comments:
Post a Comment