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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:47:44+00:00 2026-05-25T01:47:44+00:00

If I access an object inside of a synchronized method or synchronized block, are

  • 0

If I access an object inside of a synchronized method or synchronized block, are all object in that accessed element also synchronized?

Imagine there’s an object Queue having a synchronized add() and take() method, accepting and handing out the complex object Thing. Thing has a lot of lists with other different objects in it.

Now image thread Before creates Thing and puts some existing objects into Thing, modifies some of these object and so on. The Before thread adds Thing to Queue. A bit later thread After takes the Thing from Queue.

QUESTION: Will Thing and all its children/subobject be in the same state as Before left them in? Even if thread After was maybe working on one of these subelements a bit earlier? Because I image the processor for thread After might still have some cached information on that subelement (the address of that subobject is still the same). All this cached stuff would be invalidated only through accessing the father object Thing in a synchronized way?

Please don’t give answers like use the concurrency libs etc. I want to understand what is going on.

  • 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-25T01:47:45+00:00Added an answer on May 25, 2026 at 1:47 am

    The important concept in Java’s memory model is the happens-before order. Results of write actions which happen-before read actions are visible to these read actions. Other results may or may not be visible.

    The happen-before order is induced by synchronization order of actions between threads, and by the natural order of actions in the individual threads.

    If you in Before synchronize on an object (e.g. your Queue), and do all of your manipulations of Thing and its “subobjects” inside or before this synchronized-block, and After synchronized on the same Queue and reads these objects in or after the synchronized-block, then all those changes are visible to After.

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

Sidebar

Related Questions

Is there a way to get access to the full @Url helper object inside
More specifically, I need to access the request object inside the init method of
I have read that code inside a synchronized block conform to 'happens before' semantics
Is it possible to access the request object inside an struts2 action's execute() method?
Is it possible to access object properties that can only be accessed with the
Can I avoid instantiate a Db object inside of Names object to access it
I'm trying to implement a singleton class, that holds a com object inside it.
How an access to the current object inside the call to data() or maybe
I found out that I can't target a object inside the main MC if
I'm trying to add a toBool() method inside the Object object using prototype... something

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.