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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:28:03+00:00 2026-05-18T20:28:03+00:00

My doubt is do we need to make static methods as synchronized if it

  • 0

My doubt is do we need to make static methods as synchronized if it is called within synchonized non static method?

for e.g.

class Test
{

      public static void m2()
      {


      }

      public synchronized void m1()
      {

            Test.m2();
             ----
            ----
      }  

In above case do I need to make m2 as synchronized in order to avoid race condition or should I keep it as it is.

}

  • 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-18T20:28:04+00:00Added an answer on May 18, 2026 at 8:28 pm

    It depends on what your static method is doing. Do you really need it to be synchronized at all? Is it accessing shared mutable state?

    If so, you probably do need to synchronize (although I wouldn’t do so just with the synchronized modifier – I’d create a private static final variable with an object to lock on.)

    The fact that your instance method is synchronized means that no two threads will be executing it with the same target object – but two threads could both be executing m1 with different target objects, so m2 could be called twice at the same time. Whether that’s a problem or not depends on what it’s doing. If it’s not using any shared state (e.g. it’s really just computing something based on its parameters) then it doesn’t need to be synchronized at all.

    Generally speaking, it’s more important for static methods to be thread-safe than instance methods: I typically don’t make types themselves thread-safe, but instead try to use a few classes to manage concurrency, with each thread using its own set of separate objects as far as possible.

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

Sidebar

Related Questions

My doubt is do we need to make static methods as synchronized if it
Let's say I have the following method: public static int CountNonNullMembers<T>(this IEnumerable<T> enumerable) {
I have a little doubt. I need to get a list of the files
I have a doubt here, I need to show a pie-chart in SSRS, for
I am using Doctrine2 migrations. I need some answers about my doubt, I canno
I need to make a program with a limited amount of threads (currently using
SITUATION: I need to make encryption happen between my remote database and my c#
No doubt that decorator pattern is good and easy standard to enhance some method
Hey guys, I am reading these so called non-blocking techniques, but i have few
I need some help! I have no doubt this is a dumb problem that

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.