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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:27:11+00:00 2026-05-24T21:27:11+00:00

So let’s say I have a class X with a method m. Method m

  • 0

So let’s say I have a class X with a method m. Method m is NOT synchronized and it doesn’t need to be since it doesn’t really change the state of the object x of type X.

In some threads I call the method like this: x.m(). All these threads use the same object x.

By how many threads can be this method (method m) called on object x simultaneously?
Can be the fact that the method is called by, let’s say, 100 threads a bottleneck for my application?

thanks.

  • 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-24T21:27:12+00:00Added an answer on May 24, 2026 at 9:27 pm

    Other’s have answered your direct question.

    I’d like to clear up something that is could be a misconception on your part … and if it is, it is a dangerous one.

    Method m is NOT synchronized and it doesn’t need to be since it doesn’t really change the state of the object x of type X.

    That is not a sufficient condition. Methods that don’t change state typically need to be synchronized too.

    Suppose that you have a class Test with a simple getter and setter:

    public class Test {
        private int foo;
    
        public int getFoo() {
            return foo;
        }
    
        public synchronized void setFoo(int foo) {
            this.foo = foo;
        }
    }
    

    Is the getter thread-safe?

    • According to your rule, yes.
    • In reality, no.

    Why? Because unless the threads that call getFoo and setFoo synchronize properly, a call to getFoo() after a call to setFoo(...) may see a stale value for foo.

    This is one of those nasty cases where you will get away with it nearly all of the time. But very occasionally, the timing of the two calls will be such that the bug bites you. This kind of bug is likely to slip through the cracks of your testing, and be very difficult to reproduce when it occurs in production.


    The only case where it absolutely safe to access an object’s state from multiple threads without synchronizing is when the state is declared as final, AND the constructor doesn’t publish the object.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say that I have classes like this: public class Parent { public int
Let's say I have a simple UserControl with no codebehind: <UserControl xmlns= .... x:Class=TrafficLight.LightControl>
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say I have three values in PHP: a, b, c. Doesn't matter whether
Let's say I have a class like so: class Order { const STATUS_INITIALIZED =
Let's say we have a template class Area , which has a member variable
Let's say I have following POJO's using Hibernate. public class User { private String
Let's say you have a JavaScript class like this var DepartmentFactory = function(data) {

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.