Your question seemed confusing. But if I understand well what you want is that the method can not be running twice at the same time even by different customers.
Therefore, the use of a block synchronized
will solve your problem if you only have a single server process meeting requests. For example:
public class MeuServico {
private static final Object bloqueio = new Object();
public void meuMetodo() {
synchronized (bloqueio) {
// ...
}
}
}
If there are multiple lawsuits responding to requests, the situation gets a little more complicated. In this case you can have a database with a table containing a single row and a single column to simulate the mutex above. The content of this data is an identifier that tells who is currently running the method.
Which frameworks base do you use Spring or Javaee?
– Henrique Luiz