• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

caching and load balancing

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Can you suggest me how to solve this issue ?
I have a singleton class and within that class I have a static hashtable which acts as a cache by containing all my dropdown list values.
I also have a button in my app which reloads this hashtable incase any new dropdown values are added to the database.
The problem is that now when my application is being deployed.. there are going to be 2 webservers and a load balancer inbetween. My question is if I click on the reload data button mentioned above, that will only reload data in the hash on one webserver and not the other. How should I resolve this issue and what is the general practice ?
Tks a lot!

Regards
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are distributed cache products. I think a pay one is by Tangasol. There may be open source ones.

There are a few roll your own approaches too.

1) an admin screen in both web apps that you click on 'refresh cache'.
2) Check a database table on a timer. If the table has a 'refresh cache' date after the last time the cache was refreshed then refresh the cache.
3) Have an ejb or web service that you call and this service calls 'refresh' cache on both of your web apps. This could be a webservice or submission of an http page.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several ways to broadcast messages like "clear your cache now" among the cluster. JMS in pub-sub mode would seem the most natural. The "reload" button wouldn't clear a cache at all, but send a "clear cache" message. Each server in the cluster - including the one that sent the message - would get the message and clear the cache.

I worked with a vendor framework that sent messages across the cluster through a proprietary socket scheme. Their standard messages included startup, shutdown, refresh, and query status. They allowed other messages with a String argument so I sent messages like "/clearcache/cachename/". The receiver looks up "clearcache" in a map to get a classname, creates an instance and calls execute( commandString ).

Have you worked with JMS? There's a bit of a learning curve but it's not bad and this kind of thing may be very useful over the life of the system.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you just have 2 servers and not much worried about exact timing, you can follow this approach.

1. Have a servlet deployed in both the servers.
2. Whenever the hashtable is refreshed, send an intimation to the other servlet (ObjectOutputStream with hastable values or just some event to get it refreshed).
3. Servlet takes care of either updating the cache or refreshing it from DB.

~Rajesh.B
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for the reply.
Sorry, if I was not clear. Let me explain again.
I have one web app deployed on 2 servers.. so 2 copies of the web app on the 2 servers.
There is a reload button in my admin page which calls a servlet which contains the code to reload the hashmap. Now my issue is this servlet will execute on whatever server the loadbalancer sends the request to.. what should I do about the other server ? How do I call the servlet there ?
Tks
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A number of the responses answered your question. jms/web service/ejb/db/open source cache product/commercial cache product could all do what you want.
 
Raj Bhandari
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On second thoughts, I agree with you Steve. Tks!
 
He baked a muffin that stole my car! And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic