में टाइमज़ोन.सेटडिफॉल्ट परिवर्तन मैंने अभी देखा है कि जेडीके 6 के पास जेडीके 5 की तुलना में डिफ़ॉल्ट टाइमज़ोन सेट करने के लिए एक अलग दृष्टिकोण है।जेडके 6
पहले नया डिफ़ॉल्ट थ्रेड-स्थानीय चर में संग्रहीत किया जाएगा। जेडीके 6 के साथ (मैंने अभी 1.6.0.18 की समीक्षा की है) कार्यान्वयन बदल गया है, ताकि यदि उपयोगकर्ता "user.timezone" संपत्ति को लिख सकता है, या यदि कोई सुरक्षा प्रबंधक स्थापित नहीं है, तो टाइमज़ोन VM-wide बदलता है! अन्यथा एक थ्रेड-स्थानीय परिवर्तन होता है।
क्या मैं गलत हूँ? यह काफी कठोर परिवर्तन प्रतीत होता है, और मुझे इसके बारे में वेब पर कुछ भी नहीं मिला।
private static boolean hasPermission() {
boolean hasPermission = true;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(new PropertyPermission("user.timezone", "write"));
} catch (SecurityException e) {
hasPermission = false;
}
}
return hasPermission;
}
/**
* Sets the <code>TimeZone</code> that is
* returned by the <code>getDefault</code> method. If <code>zone</code>
* is null, reset the default to the value it had originally when the
* VM first started.
* @param zone the new default time zone
* @see #getDefault
*/
public static void setDefault(TimeZone zone)
{
if (hasPermission()) {
synchronized (TimeZone.class) {
defaultTimeZone = zone;
defaultZoneTL.set(null);
}
} else {
defaultZoneTL.set(zone);
}
}
जबकि पहले (JDK5 में) यह केवल था:
/**
* Sets the <code>TimeZone</code> that is
* returned by the <code>getDefault</code> method. If <code>zone</code>
* is null, reset the default to the value it had originally when the
* VM first started.
* @param zone the new default time zone
* @see #getDefault
*/
public static synchronized void setDefault(TimeZone zone)
{
defaultZoneTL.set(zone);
}