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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:51:19+00:00 2026-05-22T21:51:19+00:00

I am reading Java Concurrency in Practice and kind of confused with the thread

  • 0

I am reading Java Concurrency in Practice and kind of confused with the thread confinement concept. The book says that

When an object is confined to a thread, such usage is automatically thread-safe even if the confined object itself is not

So when an object is confined to a thread, no other thread can have access to it? Is that what it means to be confined to a thread? How does one keep an object confined to a thread?

Edit:
But what if I still want to share the object with another thread? Let’s say that after thread A finishes with object O, thread B wants to access O. In this case, can O still be confined to B after A is done with it?

Using a local variable is one example for sure but that just means you don’t share your object with other thread (AT ALL). In case of JDBC Connection pool, doesn’t it pass one connection from one thread to another once a thread is done with that connection (totally clueless about this because I never used JDBC).

  • 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-22T21:51:20+00:00Added an answer on May 22, 2026 at 9:51 pm

    So when an object is confined to a thread, no other thread can have access to it?

    No, it’s the other way around: if you ensure that no other thread has access to an object, then that object is said to be confined to a single thread.

    There’s no language- or JVM-level mechanism that confines an object to a single thread. You simply have to ensure that no reference to the object escapes to a place that could be accessed by another thread. There are tools that help avoid leaking references, such as the ThreadLocal class, but nothing that ensures that no reference is leaked anywhere.

    For example: if the only reference to an object is from a local variable, then the object is definitely confined to a single thread, as other threads can never access local variables.

    Similarly, if the only reference to an object is from another object that has already been proven to be confined to a single thread, then that first object is confined to the same thread.

    Ad Edit: In practice you can have an object that’s only accessed by a single thread at a time during its lifetime, but for which that single thread changes (a JDBC Connection object from a connection pool is a good example).

    Proving that such an object is only ever accessed by a single thread is much harder than proving it for an object that’s confined to a single thread during its entire life, however.

    And in my opinion those objects are never really “confined to a single thread” (which would imply a strong guarantee), but could be said to “be used by a single thread at a time only”.

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

Sidebar

Related Questions

So I am reading this book titled Java Concurrency in Practice and I am
I am reading this book called Java Concurrency in Practice and the author gives
I mostly use Java and generics are relatively new. I keep reading that Java
I remember reading in some Java book about any operator other than 'instanceof' for
I was reading Java Platform Performance (sadly the link seems to have disappeared from
I was reading some Java recently and came across something (an idiom?) new to
As a Java developer who is reading Apple's Objective-C 2.0 documentation: I wonder what
I am reading image files in Java using java.awt.Image img = Toolkit.getDefaultToolkit().createImage(filePath); On some
Can you recommend a Java library for reading, parsing, validating and mapping rows in
I've been reading through a lot of the rookie Java questions on finalize() and

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.