Yes, there's a big difference between caching and pooling. Pooling is a case where you have several, essentially, identical object that you would like to reuse whereas caching is where you have several distinct objects that you would like to access faster than normal.
A simple cache is really trivial to set up, however it is up to you to decide whether a trivial cache will be effective for you. If your data is truly static (i.e. you are comfortable in restarting Tomcat to reset your cache), then the simplest way to create a cache is to use a Singleton object that encapsulates access to the cache through a HashMap. The trick, however, is to ensure that you initialize the Singleton cache during the start up of the Tomcat container (using a <load-on-startup> tag in the web.xml). By doing this you do not have to worry about threading issues, as the servlets init() methods are called indvidually, and sequentially before request processing starts. This means no synchronization overhead during runtime. Once intialized, you simply fetch the objects out of the HashMap for your application. Of course, follow the other suggestions and ensure that this is really a bottleneck in you application. If your data is not that static, then the cache suddenly becomes much more complex in dealing with issues like stale data and refresh. Top that complexity with the fact that a decent database with ample memory will also cache the data as well, and you must consider how much benefit the added complexity will give you. Regards, Will Hartung ([EMAIL PROTECTED]) ----- Original Message ----- From: "Felipe Schnack" <[EMAIL PROTECTED]> To: "Tomcat Users List" <[EMAIL PROTECTED]> Sent: Monday, December 23, 2002 1:10 PM Subject: RE: Object Pooling Yes... I guess I didn't know the difference between caching and pooling. Anyway, if now I got the idea, I should use a cache for the second case, ok. There is a good opensource implementation around? And in the first case, as my objects are not "thread safe" maybe I should use a pool, shouldn't I? Or maybe the effort doesn't pay? -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
