On Sat, May 17, 2008 at 12:12 AM, Leon Rosenberg <
[EMAIL PROTECTED]> 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: [email protected]
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
Twinsen