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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:59:20+00:00 2026-06-07T16:59:20+00:00

private double value; public synchronized void setValue(double value) { this.value = value; } public

  • 0
private double value;

public synchronized void setValue(double value) {
    this.value = value;
}
public double getValue() {
    return this.value;
}

In the above example is there any point in making the getter synchronized?

  • 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-07T16:59:23+00:00Added an answer on June 7, 2026 at 4:59 pm

    I think its best to cite Java Concurrency in Practice here:

    It is a common mistake to assume that synchronization needs to be used only when writing to shared variables; this is simply not true.

    For each mutable state variable that may be accessed by more than one
    thread, all accesses to that variable must be performed with the same
    lock held. In this case, we say that the variable is guarded by that
    lock.

    In the absence of synchronization, the compiler, processor, and runtime can do some downright weird things to the order in which operations appear to execute. Attempts to reason about the order in which memory actions “must” happen in insufflciently synchronized multithreaded programs will almost certainly be incorrect.

    Normally, you don’t have to be so careful with primitives, so if this would be an int or a boolean it might be that:

    When a thread reads a variable without synchronization, it may see a
    stale value, but at least it sees a value that was actually placed
    there by some thread rather than some random value.

    This, however, is not true for 64-bit operations, for instance on long or double if they are not declared volatile:

    The Java Memory Model requires fetch and
    store operations to be atomic, but for nonvolatile long and double
    variables, the JVM is permitted to treat a 64-bit read or write as two
    separate 32-bit operations. If the reads and writes occur in different
    threads, it is therefore possible to read a nonvolatile long and get
    back the high 32 bits of one value and the low 32 bits of another.

    Thus, even if you don’t care about stale values, it is not safe to use
    shared mutable long and double variables in multithreaded programs
    unless they are declared volatile or guarded by a lock.

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

Sidebar

Related Questions

private double _value; public object Value { get { return _value; } } I
Snippets: private double memberVal; public double MemberVal { get { return memberVal; } set
Why is this valid public struct MyStruct { public MyStruct(double value) { myField =
I wrote the following: public class Point { private double _radius , _alpha; public
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
private final List<KeyListener> keyListeners= new CopyOnWriteArrayList<KeyListener>(); public void addKeyListener(KeyListener keyListener){ keyListeners.add(keyListener); } In the
i have an array with some double value inside: private double speed[] = {50,
if I have these three classes: public class PropertyDouble { private double _value; public
Given class Value : public class Value { private int xVal1; private int xVal2;
I found myself staring at code that looks similar to this: private double? _foo;

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.