0

当我currentTimeInMillis从数据库中取出时间戳并减去它时,我得到的值不正确。查看日志后,这些值似乎在 197 907 ms / 60 000 = 119.965117 分钟左右发生了一些变化。看起来像“两个小时的问题”。

MySQL 使用 SYSTEM 时区:

mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+

并且 JVM 没有参数指定时区(因此它应该拾取系统时区)。

网络服务器和数据库服务器是同一台机器。

这个问题只能在使用 Virtuozzo 的生产服务器上重现(根本不重要),而不是在我的本地主机上,它可以在使用 Java6 和 Java7 的生产服务器上重现。

使用 JDBC 将日期插入数据库中:

cityItemInsertStmt.setDate(3, new Date(System.currentTimeMillis());

并使用普通 JDBC 阅读:

cityItemEntry.setVoteDate(rs.getDate("vote_date"));

有关系统的更多信息:

Ubuntu 10.04.4 LTS
2.6.18-028stab099.3 #1 SMP 3 月 7 日星期三 15:20:22 MSK 2012 x86_64 GNU/Linux
jdk1.6.0_33 (x64) 取自 Oracle 网站并手动安装

glassfish的参数

/usr/lib/jvm/jdk1.6.0_33/bin/java -cp /home/glassfish/glassfish/modules/glassfish.jar -XX:+UnlockDiagnosticVMOptions -XX:PermSize=64m -XX:MaxPermSize=192m -XX:NewRatio =2 -Xmx2048m -Xms1024m -server -javaagent:/home/glassfish/glassfish/lib/monitor/flashlight-agent.jar -Dfelix.fileinstall.disableConfigSave=false -Dproduct.name -Djavax.net.ssl.keyStore=/home /glassfish/glassfish/domains/domain1/config/keystore.jks -Djava.awt.headless=true -Dfelix.fileinstall.poll=5000 -Djava.endorsed.dirs=/home/glassfish/glassfish/modules/endorsed:/home /glassfish/glassfish/lib/endorsed -Dfelix.fileinstall.bundles.startTransient=true -Djavax.net.ssl.trustStore=/home/glassfish/glassfish/domains/domain1/config/cacerts.jks -Dcom.sun.enterprise。 security.httpsOutboundKeyAlias=s1as -DANTLR_USE_DIRECT_CLASS_LOADING=true -Djava.security.auth.login。config=/home/glassfish/glassfish/domains/domain1/config/login.conf -Dgosh.args=--nointeractive -Dosgi.shell.telnet.maxconn=1 -Djdbc.drivers=org.apache.derby.jdbc.ClientDriver -Dfelix.fileinstall.dir=/home/glassfish/glassfish/modules/autostart/ -Dosgi.shell.telnet.port=6666 -Djava.security.policy=/home/glassfish/glassfish/domains/domain1/config/server。策略 -Dfelix.fileinstall.log.level=2 -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory -Dosgi.shell.telnet.ip=127.0.0.1 -Dcom.sun。 aas.instanceRoot=/home/glassfish/glassfish/domains/domain1 -Dcom.sun.aas.installRoot=/home/glassfish/glassfish -Djava.ext.dirs=/usr/lib/jvm/jdk1.6.0_33/lib/ ext:/usr/lib/jvm/jdk1.6.0_33/jre/lib/ext:/home/glassfish/glassfish/domains/domain1/lib/ext -Dfelix.fileinstall.bundles.new。start=true -Djava.library.path=/home/glassfish/glassfish/lib:/usr/lib/jvm/jdk1.6.0_33/jre/lib/amd64/server:/usr/lib/jvm/jdk1.6.0_33 /jre/lib/amd64:/usr/lib/jvm/jdk1.6.0_33/lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib com .sun.enterprise.glassfish.bootstrap.ASMain -domainname domain1 -asadmin-args --host,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false ,,,--echo=false,,,--interactive=false,,,start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/ glassfish/glassfish/domains,,,domain1 -instancename server -verbose false -debug false -asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli。 AsadminMain -upgrade false -type DAS -domaindir /home/glassfish/glassfish/domains/domain1 -read-stdin true/usr/lib/jvm/jdk1.6.0_33/jre/lib/amd64/server:/usr/lib/jvm/jdk1.6.0_33/jre/lib/amd64:/usr/lib/jvm/jdk1.6.0_33/ lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib com.sun.enterprise.glassfish.bootstrap.ASMain -domainname domain1 -asadmin-args --主机,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=false,,, start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/glassfish/glassfish/domains,,,domain1 -instancename server -verbose false -debug false - asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli.AsadminMain -upgrade false -type DAS -domaindir /home/glassfish/glassfish/domains/domain1 -read-stdin 为真/usr/lib/jvm/jdk1.6.0_33/jre/lib/amd64/server:/usr/lib/jvm/jdk1.6.0_33/jre/lib/amd64:/usr/lib/jvm/jdk1.6.0_33/ lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib com.sun.enterprise.glassfish.bootstrap.ASMain -domainname domain1 -asadmin-args --主机,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=false,,, start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/glassfish/glassfish/domains,,,domain1 -instancename server -verbose false -debug false - asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli.AsadminMain -upgrade false -type DAS -domaindir /home/glassfish/glassfish/domains/domain1 -read-stdin 为真0_33/lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib com.sun.enterprise.glassfish.bootstrap.ASMain -domainname domain1 -asadmin-args --host,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=false, ,,start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/glassfish/glassfish/domains,,,domain1 -instancename server -verbose false -debug false -asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli.AsadminMain -upgrade false -type DAS -domaindir /home/glassfish/glassfish/domains /domain1 -read-stdin true0_33/lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib com.sun.enterprise.glassfish.bootstrap.ASMain -domainname domain1 -asadmin-args --host,,,localhost,,,--port,,,4848,,,--secure=false,,,--terse=false,,,--echo=false,,,--interactive=false, ,,start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/glassfish/glassfish/domains,,,domain1 -instancename server -verbose false -debug false -asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli.AsadminMain -upgrade false -type DAS -domaindir /home/glassfish/glassfish/domains /domain1 -read-stdin true--echo=false,,,--interactive=false,,,start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/glassfish/glassfish /domains,,,domain1 -instancename server -verbose false -debug false -asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli.AsadminMain -upgrade假 -type DAS -domaindir /home/glassfish/glassfish/domains/domain1 -read-stdin true--echo=false,,,--interactive=false,,,start-domain,,,--verbose=false,,,--debug=false,,,--domaindir,,,/home/glassfish/glassfish /domains,,,domain1 -instancename server -verbose false -debug false -asadmin-classpath /home/glassfish/glassfish/modules/admin-cli.jar -asadmin-classname com.sun.enterprise.admin.cli.AsadminMain -upgrade假 -type DAS -domaindir /home/glassfish/glassfish/domains/domain1 -read-stdin true
4

1 回答 1

0

这与时区有关吗?我怀疑您的数据库位于不同的时区,而您的客户端/服务器位于不同的时区。我认为通常的偏好是将数据库保持在 GMT 时区。

尝试查找有关时区问题的更多信息,您可能会找到一些答案。

于 2012-07-24T08:14:23.390 回答