Ich habe gerade festgestellt, dass JDK 6 einen anderen Ansatz zum Festlegen einer Standard TimeZone als JDK5 hat.TimeZone.setDefault Änderungen in JDK6
Zuvor wurde der neue Standardwert in einer Thread-lokalen Variablen gespeichert. Mit JDK6 (ich habe gerade 1.6.0.18 überprüft) hat sich die Implementierung geändert. Wenn der Benutzer in die Eigenschaft "user.timezone" schreiben kann oder wenn kein SecurityManager installiert ist, ändert sich die Zeitzone VM-weit! Andernfalls tritt eine Thread-lokale Änderung auf.
Bin ich falsch? Dies scheint eine ziemlich drastische Veränderung zu sein, und ich konnte im Internet nichts darüber finden.
Hier ist der JDK6 Code:
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);
}
}
während vor (in JDK5) war es einfach:
/**
* 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);
}