1

セッション Bean を呼び出すために、クライアント要求を実行したいと考えています。ただし、最初のリクエストの前に 2 番目のリクエストが正常に実行される場合があります。

ejb2 ステートレス セッション Bean を使用して、順次クライアント リクエストを実行できますか?

public generate(){
    .................
    update()
    .............
}
private update(){

  debugLog(" update query for "+id);

   //code for update query

  debugLog(" execute update query for "+id);


}

2つのリクエストを同時に送信すると、次のようなログが表示されました..

 update query for 16
 update query for 16
 execute update query for 17
 execute update query for 16

しかし、私はそれをシリアルに実行したい

update query for 16
 update query for 16
 execute update query for 16
 execute update query for 17
4

1 に答える 1

1

EJB-3.x Specific :

  • You need singleton bean - @Singleton, here you are using stateless bean which might execute parallely & independently for requests in random order.

  • Now sequencing the events in order, you have to use locking mechanism at class/method level based on your requirements.

    By default, beans annoted with @Singleton are container managed & uses locking mode LockType.WRITE, explicitly can apply @ConcurrencyManagement(CONTAINER). If any of the method is being called by a client, all the other requests will have to wait for the previous call to return.

    You can also annotate at method level with @Lock(LockType.WRITE). Therefore, the sequence of the call will pertain the order in which they are called by clients.

EJB-2.x Specific :

  • You have to create singleton on your own as annotation aren't available.

  • Not sure about container managed concurrency in EJB-2.x, but synchronizing the entry method would definitely help, as it is calling other methods internally.

    Edit : Delegate the requests from the beans to a singleton utility class & synchronize method appropriately. Therefore it will resolve both, the pooling & sychronizing issue with stateless beans.

于 2012-03-27T12:13:00.733 に答える