tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ho Fat Tsang" <nam...@gmail.com>
Subject Re: understanding some tomcat code
Date Sat, 17 May 2008 11:11:32 GMT
On Sat, May 17, 2008 at 12:12 AM, Leon Rosenberg <
rosenberg.leon@googlemail.com> wrote:

> Hi,
>
>  was just browsing through tomcat code, and the following is just a
> mystery to me ->StandardSession.fireSessionsEvent(type,data):
>
>   public void fireSessionEvent(String type, Object data) {
>        if (listeners.size() < 1)
>            return;
>        SessionEvent event = new SessionEvent(this, type, data);
>        SessionListener list[] = new SessionListener[0];
> --------> WHY synchronized?
>   synchronized (listeners) {
>            list = (SessionListener[]) listeners.toArray(list);
>        }


It is kind of Snapshot Pattern i thought. Synchronize copy the
SessionListener list as toArray is not thread safety. Then further
synchronized is not required in the for loop below (as the list is a
snapshot of the original list). Thus any registration or removal of session
listener does not need to wait the complete of event firing in
StandardSession.


>
>
>        for (int i = 0; i < list.length; i++){
>            ((SessionListener) list[i]).sessionEvent(event);
>        }
>
>    }
>
>
> can someone enlighten me? :-)
>
>
> regards
> Leon
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Twinsen

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message