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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:45:48+00:00 2026-05-31T17:45:48+00:00

I got asked the following question in an interview while talking about concurrency in

  • 0

I got asked the following question in an interview while talking about concurrency in Java. I couldnt come up with a good strategy. Any ideas?

How do you share access to a resource in java without synchronizing the code?

  • 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-31T17:45:49+00:00Added an answer on May 31, 2026 at 5:45 pm

    If the resource is immutable then no synchronization is needed, but barring that, here are a few ideas:

    1. Restrict all access to read-only: if nothing is updating the resource then any number of concurrent threads can safely have read access to it.

    2. Copy the resource per subscriber: any number of threads can have their own copy of a resource and safely modify it with no impact on other threads with their own copy. (e.g. ThreadLocal)

    3. Use an atomic reference to emulate synchronization: a “getter” method use check an atomic reference (e.g. AtomicBoolean) to create a “check in” / “check out” system to ensure that only one thread has access to the resource, no synchronization needed.

    4. Use a lock from java.util.concurrent.locks: which can provide the same (or even better) functionality without using the synchronized keyword.

    Of course, the interviewer might impose additional restrictions but these are good starting points given the little information in your question.

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

Sidebar

Related Questions

Friend of mine got asked the following question in an interview recently and im
Hi guys i previously asked a question and got a good solution. here is
I asked this goofy question earlier today and got good answers. I think what
Hope this question hasn't been asked before. I've got the following working <!-- 640x920
Earlier today I asked a question about configuring log4net from code and got an
I previously asked a similar question on this topic a while back and got
I recently asked a question about Self-Joins and I got a great answer. The
I originally asked this question on ServerFault and haven't got any response and I
I asked this question before and got a great working answer. what is the
I asked a question yesterday which got answers but didnt answer the main point.

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.