Stephen Chambers
Stephen Chambers

Reputation: 71

Tomcat hangs calling TimeZone

I have this issue that is bringing down production. In an AWS/Ubuntu/Tomcat stack, the CPU's running Tomcat are jumping to 100% and when I get a thread dump, this one piece of code is constantly blocked at exactly the same place. (All the others are locked and waiting.)

"TP-Processor6" daemon prio=10 tid=0x0000000041ec2800 nid=0x41c4 runnable [0x00007f70194b5000]
  java.lang.Thread.State: RUNNABLE
    at sun.util.calendar.ZoneInfo.getTransitionIndex(ZoneInfo.java:322)
    at sun.util.calendar.ZoneInfo.getOffsets(ZoneInfo.java:248)
    at sun.util.calendar.ZoneInfo.getOffsets(ZoneInfo.java:225)
    at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2024)
    at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:1996)
    at java.util.Calendar.setTimeInMillis(Calendar.java:1109)
    at java.util.GregorianCalendar.<init>(GregorianCalendar.java:576)
    at java.util.Calendar.createCalendar(Calendar.java:1011)
    at java.util.Calendar.getInstance(Calendar.java:948)
    at com.xxx.core.util.DateUtil.modifyDate(DateUtil.java:385)
    at com.xxx.core.util.DateUtil.getDayDate(DateUtil.java:563)
    at com.xxx.core.util.DateUtil.getDayDate(DateUtil.java:573)
    at com.xxx.core.util.DateUtil.getDayDate(DateUtil.java:569)
    at com.xxx.core.util.DateUtil.splitByDays(DateUtil.java:496)
    at com.xxx.core.util.DateUtil.splitDateIntervalByIntervals(DateUtil.java:474)
    at com.xxx.core.util.DateUtil.splitDateIntervalByIntervals(DateUtil.java:436)

Upvotes: 4

Views: 1613

Answers (1)

ingyhere
ingyhere

Reputation: 13841

Wrap some better logging around things to figure out what is going on here.

Make sure your instance is specifying proper encoding and Locale -- system, tomcat container, application. Settle on GMT as a standard and try:

Calendar.getInstance ("GMT-0", Locale.US); // verify inputs

If you are getting an instance of a Calendar, why are you re-setting the date explicitly? Why not just create a new Calendar? You would then be instantiating a new Calendar:

Calendar cal = new Calendar (TimeZone zone, Locale aLocale); // new 
cal.setTimeZone("GMT-0"); 
cal.setTimeInMillis(System.currentTimeMillis ()); 

Calendar and Date objects are relatively malleable in Java, so you can change up how they function. I am guessing that there may be something not set right in the environment variables or container, such as Local or encoding that is conflicting with what is being attempted with the Calendar instance. Try specifying everything explicitly.

That's my best intuition.

Upvotes: 1

Related Questions