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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:20:58+00:00 2026-06-18T14:20:58+00:00

From the book Java concurrency in practice : To publish an object safely, both

  • 0

From the book Java concurrency in practice :

To publish an object safely, both the
reference to the object and the
object’s state must be made visible to
other threads at the same time. A
properly constructed object can be
safely published by:

  • Initializing an object reference from a static initializer

  • Storing a reference to it into a volatile field or AtomicReference

  • Storing a reference to it into a final field of a properly constructed
    object

  • Storing a reference to it into a field that is properly guarded by a
    lock.

My questions are :

  1. What are the the differences between bullet points 2 and 3 ? I am interested in the difference between volatile approach and final approach in terms of safe publication of the object .
  2. What does he mean by final field of a properly constructed object in point 3 ? Before starting the bulleted points authors already mentioned that they are talking about a properly constructed object (which I assume is not letting the this reference to escape ). But once again why did they mention about properly constructed objects ?
  • 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-06-18T14:21:00+00:00Added an answer on June 18, 2026 at 2:21 pm

    What are the the differences between bullet points 2 and 3 ?

    • volatile basically means that any writes to that field will be visible from other threads. So when you declare a field as volatile: private volatile SomeType field;, you are guaranteed that if the constructor writes to that field: field = new SomeType();, this assignment will be visible by other threads that subsequently try to read field.
    • final has quite similar semantics: you have the guarantee that if you have a final field: private final SomeType field; the write to that field (either in the declaration or in the constructor): field = new SomeType(); won’t be reodered and will be visible by other threads if the object is properly published (i.e. no escape of this for example).

    Obviously, the main different is that if the field is final, you can only assign it once.

    What does he mean by final field of a properly constructed object in point 3 ?

    If, for example, you let this escape from the constructor, the guarantee provided by the final semantics is gone: an observing thread might see the field with its default value (null for an Object). If the object is properly constructed this can’t happen.


    Contrived example:

    class SomeClass{
        private final SomeType field;
    
        SomeClass() {
            new Thread(new Runnable() {
                public void run() {
                    SomeType copy = field; //copy could be null
                    copy.doSomething(); //could throw NullPointerException
                }
            }).start();
            field = new SomeType();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From book Java Concurrency in Practice page 26: You can use volatile variables only
Code from the book Java Concurrency in Practice Listing 8.1 Why is the code
From the famous book Java Concurrency in Practice chapter 3.4.1 Final fields Just as
I'm reading the book Java Concurrency in Practice. In section 3.2 it talks about
In the book Java Concurrency in Practice , Brian Goetz says that objects passed
I found the book Java Concurrency in Practice to be an excellent guide to
This code is from the book Effective Java Object[] snapshot = list.toArray();// Locks list
I am reading Java Concurrency in Practice and kind of confused with the thread
I am a beginner in Java and am doing an exercise from a book.
I am learning Java using the book Java: The Complete Reference. Currently I am

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.