I'm trying to persist a singleton class and I'd like to ensure it remains singleton. What is the proper method to synchronize method calls in Spring WebFlux?
I have the following service method:
public Mono<SingletonClass> saveOrUpdate(SingletonClass singletonClass) {
return this.getTheSingletonClass()
.map(someLogicAndSave)
.switchIfEmpty(singletonClassRepository.save(singletonClass);
}
Should I add the synchronized keyword to the saveOrUpdate method?