tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vernon Wu <vern...@gatewaytech.com>
Subject Re: AW: How can I achieve thread safe for context attributes?
Date Fri, 20 Sep 2002 14:41:31 GMT

Thanks Ralph for the solutation. I, however, wonder whether the server will be slow down a
lot after the servlet context 
is synchronized for the operation. The context is the center object in the servlet.
 
9/20/2002 12:17:09 AM, "Ralph Einfeldt" <ralph.einfeldt@uptime-isc.de> wrote:

>
>synchronized (cxt) {
>  CurrentUsers cs = 
>    (CurrentUsers)cxt.getAttribute(WebKeys.CurrentUsers);
>  String user = (String)session.getAttribute(WebKeys.UserID);
>  cs.remove(user); // or other modification
>  // cxt.setAttribute(WebKeys.CurrentUsers, cs); 
>  // This one is not needed, as cs is just a reference to 
>  // the object that is stored in the context.
>  // You only need this if you want to replace an object in 
>  // the context with a different object. 
>}
>
>> -----Urspr√ľngliche Nachricht-----
>> Von: Vernon Wu [mailto:vernonw@gatewaytech.com]
>> Gesendet: Donnerstag, 19. September 2002 23:27
>> An: tomcat-user@jakarta.apache.org
>> Betreff: How can I achieve thread safe for context attributes?
>> 
>> 
>> 
>> I have an attribute stored in the servlet context scope. 
>> Various sessions can access it at any giving moment. It must be 
>> thread safe. How can achieve thread safe?
>> 
>> 	CurrentUsers cs = 
>> (CurrentUsers)cxt.getAttribute(WebKeys.CurrentUsers);
>> 	String user = (String)session.getAttribute(WebKeys.UserID);
>>       	cs.remove(user); // or other modification
>>       	cxt.setAttribute(WebKeys.CurrentUsers, cs);
>>  
>> 
>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:   
><mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>
>




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message