[MWy] JMS sessions

Vlastimil Babka babka at dsrg.mff.cuni.cz
Fri Apr 18 17:04:19 CEST 2008


Zdenek Louzensky wrote:
> Dobry den,
> 
> divam se na ulohu z tretiho cviceni - JMS a jsem zmateny z toho, jak se zde
> pouzivaji sessions. 
> Trida Client pouziva clientSession a eventSession, na kterych definuje
> MessageProducery clientSender a eventSender. V komentarich je napsano, ze
> jedna session a sender se pouziva pro synchronni a druha asynchronni zpravy.
> 
> Neni to zbytecne? 
> Chceme prece odlisit asynchronni a synchronni prijem zprav - tedy vytvorime
> si na jedne session 2 ruzne consumery.

Dobry den,

doporucuji procist napriklad popis Session v dokumentaci -
http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Session.html

"Once a connection has been started, any session with one or more
registered message listeners is dedicated to the thread of control that
delivers messages to it. It is erroneous for client code to use this
session or any of its constituent objects from another thread of control."

To mimo jine znamena ze pokud na Session udelate Consumer ktery bude
asynchronni (bude mit MessageListener jehoz onMessage() bude volat
nejaky thread JMS), nepujde uz na jinem Consumeru stejne Session v jinem
threadu udelat receive() - z me zkusenosti by to melo konkretne v
ActiveMQ skoncit ihned vyjimkou IllegalState.

Proto mame dve Session a na nich prislusne Consumery. Podobne by jsme
meli mit i ruzne Producery:

"One typical use is to have a thread block on a synchronous
MessageConsumer until a message arrives. The thread may then use one or
more of the Session's MessageProducers. "

Pokud tedy reagujeme na asynchronni zpravu prijatou consumerem z
eventSession, reakci by mel posilat producer take patrici eventSession.
Neni totiz obecne zaruceno thread safe chovani pokud by byl producer jen
jeden a soucasne s posilanim reakce by napr. uzivatel (coz je jiny
thread) posilal zpravu o pozadavku na nakup...

Hezky den,
Vlastimil Babka








More information about the NSWI080 mailing list