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 8832609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:34:24+00:00 2026-06-14T08:34:24+00:00

I got the following piece of code from a programmers test private String formatDate(Date

  • 0

I got the following piece of code from a programmers test

private String formatDate(Date date)
{
  String result = "";
  //….
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  result = sdf.format(date);
  //…
  return result;
}

with the additional information that several threads are using the method at once. Are there any problems with this?

My answer is that no, it should be fine (assuming that nothing else is going on in the //… parts).

My motivation is that no global or class data structures are used. The date is passed from each tread as a parameter and inside the method only local variables and local objects are being used. Thus, each thread will get and use it’s own object instance of the SimpleDateFormat class.

However, this was not the “correct” answer in the test. The “correct” answer is that the class SimpleDateFormat isn’t thread safe and that the access to that object therefore needs to be synchronized.

So, am I or the solution correct?

  • 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-06-14T08:34:25+00:00Added an answer on June 14, 2026 at 8:34 am

    Your answer is correct. SimpleDateFormat isn’t thread-safe that’s true but each method call will create an own instance so this is ok. If the SimpleDateFormat were an instance variable this wouldn’t be thread-safe (as you mentioned).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in the following piece of code I got from a book. The NSString *pPath
I got the following piece of code from SSIS Team Blog to cast the
I got the following piece of code: public class Collect { public string name{
The following piece of code is from u-boot: /* Initialize GOT pointer. ** Global
I've got the following piece of code: ... int x = 0; int y
I got following code from net and it looks everything is proper but i'm
I've got the following piece of SQL Code that is giving me a titular
I wrote the following piece of code to test my understanding of virtual inheritance.
I've got the following piece of code which exectues within no problem SELECT (
I've got the following piece of code in an aspx webpage: Response.Redirect(/Someurl/); I also

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.