Cork Kochi
Cork Kochi

Reputation: 1891

The Value set in ThreadLocal for Spring JMX works inconsistently

The Value set in ThreadLocal for Spring JMX works inconsistently

@ManagedResource(objectName = "MAN-TEST:name=SetValue", description = "Set Value for JMX")
@Component
public class ValueSetJMX {
    private static ThreadLocal<String> jmxValue = new ThreadLocal<String>();

    @ManagedAttribute
    public void setManValue(String valueJMX) {
    jmxValue.set(valueJMX)
    }

    @ManagedAttribute
    public String getManValue() {
            return jmxValue.get();
    }
}

After setting a value for setManValue , if I invoke getManValue() multiple times, the result will be sometimes null.

Is there any better way to resolve this

Upvotes: 0

Views: 84

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

I presume you mean setting/getting the value remotely.

No; you can't use a ThreadLocal for that - there is no guarantee the same RMI thread will be used for each request.

Upvotes: 2

Related Questions