Your question seemed confusing. But if I understand correctly what you want is that the method can not be running twice at the same time even by different clients.
Therefore, using a synchronized
block will solve your problem if you only have a single server process servicing requests. For example:
public class MeuServico {
private static final Object bloqueio = new Object();
public void meuMetodo() {
synchronized (bloqueio) {
// ...
}
}
}
If there are multiple processes handling requests, the situation becomes a bit 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 represented above. The content of this data is an identifier that tells you who is currently running the method.