0
votes

When I take currentTimeInMillis and subtract it with timestamp from the database I get incorrent values. After looking to logs it looks like the values have been shifted somewhat around 197 907 ms / 60 000 = 119.965117 minutes. Looks like "two hours problem".

MySQL uses SYSTEM timezone:

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

And no argument to JVM specifies the timezone (so it shall pickup system timezone).

The webserver and DB server are the same machine.

This problem is only reproducible on production server using Virtuozzo (shall not matter at all) and not on my localhost, it is reproducible on production server using both Java6 and Java7.

The dates are inserted in the database with JDBC:

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

and read with plain JDBC:

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

More info about the system:

Ubuntu 10.04.4 LTS 
2.6.18-028stab099.3 #1 SMP Wed Mar 7 15:20:22 MSK 2012 x86_64 GNU/Linux
jdk1.6.0_33 (x64) taken from Oracle website and installed manually

Parameters to the 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.policy -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
1
What does the value after you've fetched it from the database show?Jon Skeet
Please add your code how do you get these dates and substract them.dbf
Jon, I'll make more logging in production enviroment and let you know about actual timestamps, thanks for pointing it out.Mladen Adamovic

1 Answers

0
votes

Has this something to do with timezone? I suspect your DB is in different timezone and your client/server is in different timezone. I think the usual preference is to keep the DB in GMT timezone.

Try to find more on timezone issues, you may find some answers.