JDK 6에는 JDK5보다 기본 TimeZone을 설정하는 방법이 다릅니다.TimeZone.setDefault가 JDK6에서 변경되었습니다.
이전에는 새 기본값이 스레드 로컬 변수에 저장되었습니다. JDK6 (1.6.0.18)에서 구현이 변경되었으므로 사용자가 "user.timezone"속성에 쓸 수 있거나 SecurityManager가 설치되어 있지 않으면 VM의 시간대가 변경됩니다! 그렇지 않으면 스레드 로컬 변경이 발생합니다.
내가 틀렸어? 이것은 상당히 과감한 변화 인 것으로 보이며, 웹에서 그걸 발견 할 수 없었습니다.
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);
}