• <i id='LrzkB'><tr id='LrzkB'><dt id='LrzkB'><q id='LrzkB'><span id='LrzkB'><b id='LrzkB'><form id='LrzkB'><ins id='LrzkB'></ins><ul id='LrzkB'></ul><sub id='LrzkB'></sub></form><legend id='LrzkB'></legend><bdo id='LrzkB'><pre id='LrzkB'><center id='LrzkB'></center></pre></bdo></b><th id='LrzkB'></th></span></q></dt></tr></i><div id='LrzkB'><tfoot id='LrzkB'></tfoot><dl id='LrzkB'><fieldset id='LrzkB'></fieldset></dl></div>
    <tfoot id='LrzkB'></tfoot>
    <legend id='LrzkB'><style id='LrzkB'><dir id='LrzkB'><q id='LrzkB'></q></dir></style></legend>

          <bdo id='LrzkB'></bdo><ul id='LrzkB'></ul>

        <small id='LrzkB'></small><noframes id='LrzkB'>

      1. JDK6 中的 TimeZone.setDefault 更改

        TimeZone.setDefault changes in JDK6(JDK6 中的 TimeZone.setDefault 更改)

        <small id='hQM7I'></small><noframes id='hQM7I'>

            • <legend id='hQM7I'><style id='hQM7I'><dir id='hQM7I'><q id='hQM7I'></q></dir></style></legend>
              <i id='hQM7I'><tr id='hQM7I'><dt id='hQM7I'><q id='hQM7I'><span id='hQM7I'><b id='hQM7I'><form id='hQM7I'><ins id='hQM7I'></ins><ul id='hQM7I'></ul><sub id='hQM7I'></sub></form><legend id='hQM7I'></legend><bdo id='hQM7I'><pre id='hQM7I'><center id='hQM7I'></center></pre></bdo></b><th id='hQM7I'></th></span></q></dt></tr></i><div id='hQM7I'><tfoot id='hQM7I'></tfoot><dl id='hQM7I'><fieldset id='hQM7I'></fieldset></dl></div>
                <bdo id='hQM7I'></bdo><ul id='hQM7I'></ul>
                  <tbody id='hQM7I'></tbody>

                  <tfoot id='hQM7I'></tfoot>
                1. 本文介绍了JDK6 中的 TimeZone.setDefault 更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我刚刚注意到 JDK 6 设置默认 TimeZone 的方法与 JDK5 不同.

                  I just noticed that JDK 6 has a different approach to setting a default TimeZone than JDK5.

                  以前,新的默认值将存储在线程局部变量中.使用 JDK6(我刚刚查看了 1.6.0.18),实现发生了变化,因此如果用户可以写入user.timezone"属性,或者如果没有安装 SecurityManager,则时区会在 VM 范围内更改!否则会发生线程局部变化.

                  Previously the new default would be stored in a thread-local variable. With JDK6 (I just reviewed 1.6.0.18) the implementation has changed, so that if the user can write to the "user.timezone" property, or if there is no SecurityManager installed, the timezone changes VM-wide! Otherwise a thread-local change occurs.

                  我错了吗?这似乎是一个相当大的变化,我在网上找不到任何关于它的信息.

                  Am I wrong? This seems to be quite a drastic change, and I couldn't find anything on the web about it.

                  这里是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 <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 中)它只是:

                  while before (in JDK5) it was simply:

                   /**
                    * 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);
                   }
                  

                  推荐答案

                  搜索bug数据库其实是个好主意:)

                  Searching the bugs database was actually quite a good idea :)

                  http://bugs.sun.com/view_bug.do?bug_id=6352812

                  还有(重新文档):

                  http://bugs.sun.com/view_bug.do?bug_id=6181786

                  总结:JDK 1.5 是该规则的一个例外,JDK 1.6 一切都恢复了正常",根据文档,时区更改是 VM 范围内的.

                  Summary: JDK 1.5 was an exception to the rule, with JDK 1.6 things are back to 'normal', which, according to the docs, is that a timezone change is VM wide.

                  这篇关于JDK6 中的 TimeZone.setDefault 更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  <legend id='nOjQD'><style id='nOjQD'><dir id='nOjQD'><q id='nOjQD'></q></dir></style></legend>

                  <small id='nOjQD'></small><noframes id='nOjQD'>

                    <bdo id='nOjQD'></bdo><ul id='nOjQD'></ul>

                      • <tfoot id='nOjQD'></tfoot>
                          <i id='nOjQD'><tr id='nOjQD'><dt id='nOjQD'><q id='nOjQD'><span id='nOjQD'><b id='nOjQD'><form id='nOjQD'><ins id='nOjQD'></ins><ul id='nOjQD'></ul><sub id='nOjQD'></sub></form><legend id='nOjQD'></legend><bdo id='nOjQD'><pre id='nOjQD'><center id='nOjQD'></center></pre></bdo></b><th id='nOjQD'></th></span></q></dt></tr></i><div id='nOjQD'><tfoot id='nOjQD'></tfoot><dl id='nOjQD'><fieldset id='nOjQD'></fieldset></dl></div>
                            <tbody id='nOjQD'></tbody>