Web tier: servlets, JSP, Web frameworks: Click Counter
Hi All, Presently we have a servlet counting the number of click on a page and storing the details in the DB. Currently we are persisting the information in DB on every click. No we want to change store the information in a bulk i.e. we need to temproraly persist the click details somewhere. We are planning to use a syncronized static collection object (along with its getter and setter methods) to store this. However we want to know if there is any better solution to this rather than using static variable as i guess we can have performance issues with static variables. cheers amit
may be you can consider using a message driven bean. So, on every click, post a message, and let the message driven bean call the persistence api to persist. And regarding when the actual persistence happens can be decided by the persistence layer i.e. it can buffer the data and do a bulk update or write them on each invocation etc. Thus, you need not prepare your own datastructure to maintain the clicks and periodically persist etc. And, you also achieve good performance (as far as the client is concerned) because the whole task is achieved asynchronously. Further, you have to fine tune the persistence with either bulk update or individual update etc, which is transparent.
Add a one pixel transparent image to your web pages and intercept the requests to that image through a filter and do what ever you like in that filter.
AMIT:We are planning to use a syncronized static collection object (along with its getter and setter methods) to store this.Wont work if you are using multiple JVMs (common scenario in a production deployment)
DAVID:may be you can consider using a message driven bean. So, on every click, post a message...Too n/w (and probably cpu/memory) intensive.
BISWA: Add a one pixel transparent image to your web pages..Nice! My 2cents: Use a distributed cache (like ehcache) which is able to autoflush/persist to a db based on a required buffer/cache size.