Pergunta

I have a guess that there is an incorrect code in our codebase but I am not sure. So we have got en EJB like this:

@Stateless
public class MyEjb {
  private static Something sg = new Something();
  public void doSomething() {
    sg.execute();
  }
}

The class Something is a normal class:

public class Something {
  public void execute() {
    ...
  }
}

As the MyEJB is stateless EJB so the method doSomething can be called more times simultaneously.

Here comes my questions: if the doSomething() has been called twice at the same time then one of the calls will be blocked until the first call finishes? My guess is that it is blocked as there is just one static instance.
If I am right the code above is not good as the method 'execute' of class 'Something' is a bottleneck for my EJB.

Thanks, V.

Foi útil?

Solução

Both calls will run simultaneously, unless you restrict the access using a "synchronized" block or a "Write Lock".

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top