做网站的客户需求搭建网站
我刚刚注意到JDK 6有一种不同的方法来设置默认的TimeZone比JDK5.
以前,新的默认值将存储在线程局部变量中.使用JDK6(我刚刚评论过1.6.0.18),实现已经改变,所以如果用户可以写入“user.timezone”属性,或者如果没有安装SecurityManager,则时区改变了VM-wide!否则发生线程本地更改.
我错了吗?这似乎是一个非常大的变化,我没有找到关于它的任何网站.
这是JDK6代码:
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 TimeZone
that is
* returned by the getDefault
method. If zone
* 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 TimeZone
that is
* returned by the getDefault
method. If zone
* 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);
}