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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:49:19+00:00 2026-06-17T23:49:19+00:00

StringBuffer can handle multiple threads through synchronization If your text can changes, and will

  • 0

StringBuffer can handle multiple threads through synchronization If your text can changes, and will be accessed from multiple threads, use a StringBuffer because StringBuffer is synchronous.

Can anyone explain me when does the Multithreading happen? Do we create threads in our program implementing runnable interface or extending Thread class or is it OS based?.

  • 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-17T23:49:20+00:00Added an answer on June 17, 2026 at 11:49 pm

    The threading can happen any number of ways. If you are creating threads (e.g. extends Thread) or if you are creating objects that get passed off to a threading model of some kind (e.g. implements Runnable) or even if you just have code somewhere that handles something like events (e.g. a callback function). How the threads are created isn’t important. In any case, when you have something like this:

    public String someMethod()
    {
        StringBuilder b = new StringBuilder();
        b.append("Some Method");
        return(b.toString());
    }
    

    You know that is thread safe. Any access to the StringBuilder‘s append() method doesn’t need to by synchronized. However, if you have something like this (just an example):

    public class Test
    {
        StringBuffer b;
    
        public Test()
        {
            b = new StringBuffer();
        }
    
        public String someMethod()
        {
            b.append("Some Method");
            return(b.toString());
        }
    }
    

    Here, you can see that more than one “thread” of execution could call someMethod(), and since they would all be access the StringBuffer, it needs to be synchronized. It could be the case that only one thread ever calls the method at any one given time, but the way this is written doesn’t prohibit 2 threads calling it at the same time. If a StringBuilder is used (not thread safe) you’re likely to run into problems.

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

Sidebar

Related Questions

If your text can change and will only be accessed from a single thread,
I have a problem that I can't get through. I just started to use
StringBuffer sb=new StringBuffer(Hello); sb.append(welcome);//working sb.concat(hi);//not working Why can't i use concat here??
I'm trying to retrieve data from http://api.freebase.com/api/trans/raw/m/0h47 As you can see in text there
How can we re assign the value of a StringBuffer or StringBuilder Variable? StringBuffer
Why does StringBuffer/StringBuilder does not override the equals() , hashcode() methods from object? Please
Can anyone tell me if they know how to use the Google Chart API
I was thinking about creating a class (like String, StringBuffer etc). This can be
Can the following code cause a memory leak? Would using a StringBuffer actually improve
A lot of text is to be appended to a StringBuffer object. Later this

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.