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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:55:28+00:00 2026-05-25T23:55:28+00:00

when thread 1 has the intrinsic lock of an object because of synchronized(object) {

  • 0

when thread 1 has the intrinsic lock of an object because of

synchronized(object) {
...
}

is it possible to call

object.method()

from thread 2 or not respectively do I need to type

synchronized(object) {
object.method();
}

in thread 2 to prevent it from calling the method while thread 1 is holding the lock?

In my case I got ConcurrentModificationExceptions while iterating over a Map and I tried to prevent modifications from other threads by locking the map. And I know that often the reason for ConcurrentModificationExceptions is that the map is changed during iteration but I’m quite sure that this is not the case in my case because there are only “get”-statements and one method call in the iteration, so there can’t happen any modification.

Thanks in advance.

Binabik

  • 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-25T23:55:28+00:00Added an answer on May 25, 2026 at 11:55 pm

    Synchronization in Java is entirely co-operative – if the second thread doesn’t choose to try to acquire the monitor (and if there’s nothing in the method which tries to do so) then it won’t automatically lock.

    It’s not that the object “is locked” – it’s that one thread owns the lock associated with the object. The object itself can still be accessed; if it doesn’t need the lock, it won’t block.

    Note that you can get a ConcurrentModificationException even within a single thread if you try to iterate over it and change it within the same loop, e.g.

    // Not safe: will throw an exception
    for (Map.Entry<String, String> entry : map.entrySet()) {
        if (entry.getKey().equals("foo")) {
            map.put("bar", "Hello");
        }
    }
    

    It’s possible that this is what’s going on in your code, but we can’t tell as you haven’t shown us any code. If you can present a short but complete program demonstrating the problem, we’re much more likely to be able to work out what’s going on.

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

Sidebar

Related Questions

I know that it is not possible to restart a used Java Thread object,
In ASP.NET we use async methods because the Thread Pool has limited slots, and
Is there any way to find out from threadId , if a thread has
Is there a way to tell if a thread has exited normally or because
Does anyone know if it is possible to detect when a new thread has
It is possible to get stacktrace using System.Diagnostics.StackTrace, but thread has to be suspended.
In a multi-threaded java program, what happens if a thread object T has been
I found the method of JavaDoc: Returns: true if this thread has been interrupted;
I have a multithreaded application, where each thread has a variable of integer type.
I found that each thread still has its own registers. Also has its own

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.