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

  • Home
  • SEARCH
  • 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 8159019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:47:20+00:00 2026-06-06T17:47:20+00:00

Reading through this excellent article about safe construction techniques by Brain Goetz, I got

  • 0

Reading through this excellent article about safe construction techniques by Brain Goetz, I got confused by a comment given inside the listing 5. Here is the code snippet:

public class Safe { 

 private Object me;
 private Set set = new HashSet();
 private Thread thread;

 public Safe() { 
 // Safe because "me" is not visible from any other thread
 me = this;

// Safe because "set" is not visible from any other thread
 set.add(this);

// Safe because MyThread won't start until construction is complete
// and the constructor doesn't publish the reference
   thread = new MyThread(this);
}

public void start() {
   thread.start();
 }

private class MyThread(Object o) {

private Object theObject;

public MyThread(Object o) { 
  this.theObject = o;
}

...
 }
}

Why does he say this about me ? // Safe because "me" is not visible from any other thread. Can’t two threads simultanouesly access the instance variable me?

  • 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-06T17:47:21+00:00Added an answer on June 6, 2026 at 5:47 pm

    The only point is that while the constructor is running, you are not leaking this by setting it to a private property. After the constructor completes and the caller receives the this reference of the object, which is obviously the me reference as well, it can publish it to any thread, so indeed it will be accessible to any thread. But that was not the point Goetz was making.

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

Sidebar

Related Questions

I've been wondering about this for a while after reading through an interesting article
I'm reading through the TAP Whitepaper , and am confused by this sample given
When reading through parfib.hs code on github, I saw this comment about memory allocation
I was reading through this link about the state pattern. Is it looks like
I was reading through this interesting post about using JavaScript to generate an image
I was reading through K&R and i came across this example about uncertainty in
I was reading Stoyan Stefanov's excellent article about JS domain sharding for image files
I was reading through this question What's a RDF triple? and the excellent answers
I was reading through this: http://www.postgresql.org/about/ And I saw this: An enterprise class database,
I was reading through this article: http://aws.typepad.com/aws/2008/12/running-everything-on-aws-soocialcom.html And I was wondering if this was

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.