Hello everyone,
Forgive me if this doesn't belong here and kindly point me to the right direction, as my question is based on Java-Scala inter-operable code base that I am working on.
I have
public static ConcurrentHashMap<String, Long> certMetrics = new ConcurrentHashMap<String, Long>();
in a Java class that is invoked in scala code.
This is read in scala as
if (channelBuilder.certMetrics.isPresent) {
val certMetrics = channelBuilder.certMetrics.get
certMetrics.forEach((key, value) => metricsGroup.newGauge(key, () => {value}, providerTag))
}
This works fine when the server starts. This is used by yammer and exposed as JMX.
However, when the value of certMetrics gets updated from the base java class, the updated value doesn't get reflected where this is populated, which is in the scala code. We have verbose logging in java when the certmetrics gets updated, so I am sure that the value is getting updated, and it is thrown into the logs, but the jmx metric values doesn't reflect the value that it gets updated to.
My intution is, the concurrenthashmap, or the value which is a Long, is cloned rather than referenced, but please correct me if I am wrong.
I don't want to run a periodic task here in a thread that refreshes the data, unless that's the only option here.
What am I doing wrong here?
Thanks.