Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4533540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:10:08+00:00 2026-05-21T14:10:08+00:00

I’ve been trying to figure out this bug for few days. I have narrowed

  • 0

I’ve been trying to figure out this bug for few days. I have narrowed the issue down to a test case as follows. Again, this is a test case that causes the bug to happen. The function (at this point) is not a practical one, but just trying to figure out the bug.

Server is running:
– Tomcat 6
– OpenJDK 1.6.0_17
– CentOS 5.5

I have a simple Class file with the following method Static Method and Static variable declaration:

public static java.text.SimpleDateFormat displayDateSDF1 = new java.text.SimpleDateFormat("MM/dd/yyyy");

public static java.util.Date getSubDateMini(String inputDate)
{
    java.util.Date testObj = null;
    try
    {
        testObj = displayDateSDF1.parse("01/01/2000") ;
    }
    catch (Exception e)
    {
    }
    return testObj;
}

Testing in Tomcat:

When I run this method, I’d expect to get the same result every time, right? However, if I call this method from a JSP, I get the expected result of a Date object with value 1/1/2000 about 99.9% of the time. However, sometimes I get an unexpected data object passed back with a seemingly random date value.

To test this, I created a JSP with the following code segment in it:

for (int i=0; i<200000;i++)
{
    java.util.Date testObjLib = TestDate.getSubDateMini("") ;
    if (testObjLib!=null&&!testObjLib.toString().equalsIgnoreCase("Sat Jan 01 00:00:00 PST 2000"))
    {
            out.print("<br>"+testObjLib+"");
    }
}

Some dates that appear are as follows:

Wed Jan 01 00:00:00 PST 1

Fri Aug 01 00:00:00 PDT 2166

In 200,000 runs, I get approximately 50 bad dates which gives an error rate of ~0.025% but again it’s random. I’ve run this loop with 10 iterations and received an error. Sometimes it runs the loop with 200,000 and all dates look good.

Testing in Java:

Running this loop via a console/terminal app in CentOS with the same loop, I have not seen this error happen yet. I increased the loop to 10,000,000 and had no false results as of yet.


I can understand out of memory or some thrown error (which would result in a null value) but not corrupt/inconsistent data. I built up a new server from scratch with Tomcat 6 and also tried Tomcat 5.5 and both have the same results. I have not tried Tomcat 7.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:10:08+00:00Added an answer on May 21, 2026 at 2:10 pm

    SimpleDateFormat is not thread-safe.

    This means that when it is accessed from multiple threads, unexpected results can be observed. And tomcat is serving each request from a separate thread, so whenever two requests are made at the same time, the problem would arise.

    You have a number of options:

    • instantiate the SimpleDateFormat on each call of the method (rather than making it static)
    • if you need the format more than once per thread, use a ThreadLocal to store it.
    • alternatively use joda-time, where DateTimeFormat is thread-safe.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.