WebService synchronous

0

I have a RESTful WebService developed in Java.

I need a method (service) that is synchronous. But I can not do this on the client side, it has to be done on the WebService side, because this service can only be requested once only once. Another application can only request the method (service) if it is not running.

How can I do this on the WebService side?

    
asked by anonymous 30.01.2017 / 11:46

1 answer

0

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.

    
30.01.2017 / 16:58