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

  • Home
  • SEARCH
  • 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 8434421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:39:01+00:00 2026-06-10T06:39:01+00:00

I am writing a private utility method in a Spring Controller. I need to

  • 0

I am writing a private utility method in a Spring Controller.

I need to use either StringBuffer or StringBuilder. The former is thread-safe, the latter is not, but the latter is much faster.

Basically, it looks like this:

private String buildTextToDisplay() {
    StringBuffer sb = new StringBuffer();
    sb.append( ... );
    return sb.toString();
}

Obviously, I don’t want two sessions to call this simultaneously and return garbage.

  • 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-10T06:39:03+00:00Added an answer on June 10, 2026 at 6:39 am

    Since sb is a local variable, it doesn’t need to be thread safe. (Each thread would have its own reference to a unique StringBuilder, right?)

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

Sidebar

Related Questions

Instead of writing the following non-thread safe method. private static final Calendar calendar =
When writing a private method that has no need to access other members of
If I'm writing a class, when do I make a method private, versus protected?
I am writing a utility unit for the SetWindowsHookEx API. To use it, I'd
I am writing a small file download utility. The DownloadFile() method is called on
I am writing a Flex application for use on a private intranet with no
While writing this method for a custom NUnit Constraint. private void AddMatchFailure<TExpected, TActual>(string failureName,
Is it good practice to use the private field, or the property, when writing
So I am writing a simple inbox private message system. My table schema is
I tried writing this class #include <memory> class ContainerUnique { public: ContainerUnique(void); ~ContainerUnique(void); private:

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.