tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Einfeldt" <ralph.einfe...@uptime-isc.de>
Subject AW: How can I achieve thread safe for context attributes?
Date Fri, 20 Sep 2002 07:17:09 GMT

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>


Mime
View raw message