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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:05:45+00:00 2026-06-05T07:05:45+00:00

as titled. I have use synchronized to guard multi-thread write. but I want know

  • 0

as titled. I have use synchronized to guard multi-thread write. but I want know if I need add volatile to guard read . (as we know, I can use synchronized to guard read too, but it will prevent read and write concorrently. what’ more ,if I use reentraent lock. it will prevent too.)

private volatile BigDecimal cacheMiss = BigDecimal.ZERO;

public  BigDecimal getCacheHit() {
    return cacheHit;
}

public void increaseCacheMiss() {
    synchronized (cacheMissLock) {
        this.cacheMiss = this.cacheMiss.add(STEP);
    }
}
  • 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-05T07:05:46+00:00Added an answer on June 5, 2026 at 7:05 am

    If cacheMiss can be updated from several threads, then it needs to be declared volatile if you absolutely need to read the latest value. Otherwise a thread may be reading a thread-local value (stashed in a register or core cache), not bothering to go out to main memory to see the latest value.

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

Sidebar

Related Questions

Yes, I know that in ASP.NET MVC you have to use ViewModels. But I'm
I have an array of strings that I want to use for button titles
I don't know which title I should use for this question. I have a
I want to make IPC, but I cannot use blocking mechanism (SendMessage, PIPE, TCP),
I want to install XCode 4.2 on my mac. I have the dmg, but
I have a workbook with three worksheets titled FY09, FY10, and FY11. I need
Hi I have to use noConflict method in my project. But I have a
I already started this in javascript so I don't want to use jquery but
As titled. I have a class that implement IComparable which need for sorting. I
As titled. We all know if we want a class to be comparable 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.