... there can be multiple clients call[ing] setName() via jconsole, do I need need to synchronize the getter and setter?
Yes, you probably should if multiple threads are calling the getters and setters -- just like you should if multiple local threads are calling the getter and setter. As @user454322 pointed out, using the volatile
keyword to accomplish the memory synchronization is also appropriate.
Synchronization of some form is necessary for two reasons. Firstly, multiple JMX operations can be running at the same time meaning that getter and setter race-conditions can happen. Secondly, even if the setter happens before the getter, there is no guarantee that the JMX thread has the updated value without synchronization. It depends on how important it is that each thread gets the last value of the name. If all threads must see the very last name that was set, then you'll need to keep things well synchronized
.
This said, we have a lot of unsynchronized JMX getter methods on statistics and other diagnostic information and expect that the JVM will synchronize the various counters at some point.