This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I need to find a way to improve performance of my application. here is the scenario,
Its a J2ee application. The client will send the request to the servlet (programmatic) after every 10 seconds. The servlet will query the database and return the results. Currently there are few users but in future when the user base increases, this approach wont work as there will be many concurrent requests and hence load on the database and the application.
I was thinking of writing a thread which will ping the database after every 10 seconds and store the "Superset" of the data in an application wide object (e.g. a table structure in app context). The servlet will query this object instead of the database on each request.
Is it a right approach? Also in case of "Clustered Environment" will this work? My concern is whether app. context is replicated over clusters?
Can any one suggest me a better approach or tell me if I am missing something.
Any help is really appreciated
Thanks and Regards,<br />Sameer R. Mhaskar.<br />Technology Analyst
Sameer, This is a good approach. Do you have users 24 hours a day? If not, you might want to write it so you only go to the database if there has not been a request in the last <however long>. That way you don't have database traffic all day even when nobody is on the system.
Some servers have built in caching layers - you might want to check if yours does before writing your own. A built in cache will replicate across a server. Your own will not.
Which turns into a question of whether your application can tolerate data that is X seconds out of date. Some threshold is usually ok because you can't guarantee the data will be correct by the time the user sees it anyway. (processing, network traffic and the like)
Its a position monitoring system for a stock lending application. The users are logged in all the time but the data which is around 10 seconds old is tolerated. That is the reason I was planning to write a thread and update the data in cache every 10 seconds. I am using Web logic in a clustered environment. How can I use caching mechanism in Web logic? Any thoughts...
Cache refresh strategy you are planning to adopt will work for a single standalone server.
In a clustered environment,you either need to use a distributed cache (such as memcache,EH cache etc) OR build a mechanism to ensure local cache consistency using some messaging system such as JMS. [ August 30, 2008: Message edited by: Ajay Saxena ]
author & internet detective