Will my Spring Rest Controller using a @Service class via @Autowired and @Service class having a critical section - synchronized on an instance field
private final Object modifyIndexLock = new Object(); be ready for distributed deployment or I need to synchronize in some other way?
Underlying resource being a Lucene Index Writer and at any point of time, only one writer can be opened. A thread trying to open a writer while its already open will fail. I don't want my thread to fail but wait.
Code works OK for a single server app deployment but I guess , it will fail in distributed environments since there will be multiple instances of @Service in each JVM resulting in different locks while underlying protected resource being a single one.
synchronized(modifyIndexLock){
//Open & use writer the close
}
A pool of writers are not available but only a single instance.