Synchronous webservice

Asked

Viewed 133 times

0

I have a Restful Webservice developed in Java.

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

How can I do that on Webservice’s side?

  • Which frameworks base do you use Spring or Javaee?

1 answer

0

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.