I have a Java application that depends on date/time of the system to check for new and old email messages.
While I was checking the Java application log, I found that the server timezone has changed. This caused the application to fail in doing its job.
What could be the reason of this sudden change in the server timezone? How can I prevent such problems in the future.
I am using ubuntu server 8.04.
Does your application check the time by checking Unix time (time_t, seconds since the epoch), or does it check just human-expressed time, neglecting the timezone?
If the latter, I fear you may have made a coding error. The timezone can be set and changed on a process-by-process basis, as easily as changing the TZ environment variable; try
Note that this is an environment variable, and thus inheritable by the children of the running process. If the java process happens to be restarted by someone who has TZ set to something you didn't expect, and your startup file doesn't force TZ, then java will be running with an unexpected timezone.
TZ is by no means the only way of setting the timezone; I wanted to mention this to show you that Unix is designed to allow the timezone to be a personal convenience, much like your shell prompt or your PATH. If you need a process to have a particular view of timezone, you need to make sure that it sets that when it starts up.