Home > Blockchain >  Will static synchronized method help to resolve race condition in Microservice environment which has
Will static synchronized method help to resolve race condition in Microservice environment which has

Time:02-16

In a microservice environment, if multiple instances of the same pod are present, will separate classes be created for each instance or the class resource is read from a common place for both the instances?

I was thinking since Static Synchronized method locks the class level we can prevent race condition. Any input would be helpful.

CodePudding user response:

The 'static' or 'synchronized' keywords apply only for a single process. As soon as you run multiple instances it won't help, no matter if on the same machine, same container or different containers/pods or machines.

This might be helpful as alternative: https://www.jobrunr.io/en/ or https://github.com/lukas-krecan/ShedLock

  • Related