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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:27:30+00:00 2026-05-27T00:27:30+00:00

I read that JVM achieves the synchronization by copying data of shared variable from

  • 0

I read that JVM achieves the synchronization by copying data of shared variable from the main memory to the thread’s working memory according to this link.

enter link description here

for example, there is a class like this.

class Test {
private Test2 test2 = new Test2();

public void print1() {}

public synchronized void print2() {
    test2.print();
}

}

If this Test class is executed in multiple threads and “print2” method is executed in one thread, I think that a lock on Test is acquired by one Thread and other threads have to wait until the lock is released.

Now I have a question. If a lock on Test is acquired by a Thread, does it mean that data of Test and Test2 is copied from the main memory to a thread’s working memory? The reason that I am saying is that “synchronized” keyword is used at instance method level and test2 is a instance variable of Test class.

I am just trying to clarify what is copied from the main memory to a thread’s working memory.

Please correct me if I am wrong.

  • 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-27T00:27:31+00:00Added an answer on May 27, 2026 at 12:27 am

    In brief, all shared variables will be copied (i.e. written from cache to main memory so all threads have the same data) when you use synchronized. When you use volatile, only the one volatile variable is guaranteed to be copied.

    I found this to be a helpful resource which touches on the topic.

    http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html

    EDIT: Regarding your comment, section 17.6 of the specification answers your question:

    Let T be any thread, let V be any variable, and let L be any lock.
    There are certain constraints on the actions performed by T with
    respect to V and L:

    Between a lock action by T on L and a subsequent use or store action
    by T on a variable V, an assign or load action on V must intervene;
    moreover, if it is a load action, then the read action corresponding
    to that load must follow the lock action, as seen by main memory.
    (Less formally: a lock action acts as if it flushes all variables from
    the thread’s working memory; before use they must be assigned or
    loaded from main memory.
    )

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

Sidebar

Related Questions

I read from sun website that for every reference jvm is creating one immutable
I read that JVM stores internally short, integer and long as 4 bytes. I
Our design has one jvm that is a jboss/webapp (read/write) that is used to
I've often read that in the Sun JVM short-lived objects (relatively new objects) can
I read that you could call JavaScript code from a Java Applet by calling
I read somewhere that java can allocate memory for objects in about 12 machine
I read that Domain Driven Design is about concentrating on the problem domain instead
I read that SQL exceptions are treated as normal exceptions in managed SPs; I
I read that you should define your JavaScript functions in the <head> tag, but
I read that defined styles are located at C:\Program Files\Microsoft Office\Office12\Bibliography\Style I use ISO

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.