I can understand wanting to use a HashMap over a Hashtable (the ability to store null values for example). But if you want to serialize access to the HashMap you can use the following according to the javadoc documentation:
Map m = Collections.synchronizedMap(new HashMap(...)); I realize this isn't really a tomcat issue. Richard At 03:29 PM 2002-05-15 -0400, you wrote: >Howdy, >You may want to worry more about the HashMap's put() calls than the >get() calls. HashMap in itself is NOT synchronized, Hashtable is. If >you think there can be multiple threads writing to this hint map, then >those are the ones you should consider synchronizing. (Or using >Hashtable). > >It's also a big of a different story if you're iterating over or >otherwise manipulating the key or entry set of the hint map. If you're >only using get() calls, it's a bit easier. The iterators are fail-fast, >so if something modifies your hint map while you're iterating, you'll >get a ConcurrentModificationException. But it seems like you're just >getting, so that's not a concern. > >And this whole thing is not really a tomcat issue ;) Unless you were >thinking of using SingleThreadModel for something in this webapp that >affects the hint bean? > >Yoav Shapira >ChemInformatics > > > >-----Original Message----- > >From: Michael Molloy [mailto:[EMAIL PROTECTED]] > >Sent: Wednesday, May 15, 2002 3:09 PM > >To: [EMAIL PROTECTED] > >Subject: To synchronize or not? > > > >I've working on an application that will be used by 150 people > >concurrently. > >When Tomcat starts up, I've got a servlet that creates a class that > >contains > >about 800 html input tag hints. For example, when a user clicks into an > >input > >field, the hint for that field displays in the status bar of their >browser. > > > >Everytime a user logs in, s/he gets a LoginBean class. This class has a > >reference to the HintBean class. All of the html pages have forms that > >include in their tags a getProperty such as the following: > > > ><jsp:getProperty name="loginBean" property="childFirstName" /> > > > >The relevant parts of LoginBean are as follows: > > > >public LoginBean(HintBeant hints) { > > this.hints = hints; > >} > >public String getChildFirstName() { > > return hints.get("childFirstName"); > >} > > > >So, everyone has their own class with the specific getters for each >text > >field hint, but all of those getters point to a single class (HintBean) > >that > >is in the application scope. > > > >All of the hints are stored in a HashMap inside the HintBean, so the >above > >method just calls HashMap.get(String s) to return the hint. > > > >My question is, should I make HintBean.get(String s) synchronized? Or >is > >there no chance that anyone will get the wrong text? And if not, why >not? > > > >Thanks for any help. > >--Michael > > > >-- > >To unsubscribe, > e-mail: <mailto:tomcat-user->[EMAIL PROTECTED]> > >For additional commands, e-mail: > <mailto:tomcat-user->[EMAIL PROTECTED]> > > >-- >To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
