My question is regarding locking on an object instance in Java.
I've got the following method that can be called by multiple threads at the same time. I've chosen to lock on an object instance since i'd like to allow concurrent processing as long as one instance is being accessed only by one thread at a time.

My simplified code goes something like this where I am basically locking on a local variable.
Would this really be satisfying what I need? I've been reading suggestions never to lock on an object that might change and i'm suddenly unsure whether this is what i'm doing after all!

Thanks!

Edit:

Oh dear ... I'm just realizing that my attempt to simplify my code for posting might be a bit misleading.

I am renaming the methods I previously called "getInstance" to something else ("getFromMap") to demonstrate that the method call is custom code which returns a reference to an object in a hashmap. 

Would the previous answer still hold? apologies for confusion!

```
public boolean processInput(...) {
if(message == 1) {
    Class_0 context = (Class_0)Class_0.getFromMap("xyz");
    synchronized(context) {
        context.setContextParams("abc");
       context.evaluateContextRules(message, this);
    }
} else if(message == 2) {
    Class_1 context = (Class_1)Class_1.getFromMap("efg");
    synchronized(context) {
        context.setContextParams("abc");
        context.evaluateContextRules(message, this);
    }
}
.....
}

```