• Post Reply Bookmark Topic Watch Topic
  • New Topic

static block and clustering

 
varnika Raman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servelt containing a static block. When this servlet runs in clustered environment, I don't want two servlet instances initializing the static block seperately and do the work. How do you think, I can solve this issue.
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can u enhance the clarity of the question ? You are talking of "static" block and talking about multiple instances . Following is a solution from my understanding of the question, Static block can be well replaced by a static method and that should be solving the problem.
Cheers,
Gaya3
 
varnika Raman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gayathri,
This is my question, I have a servlet which has a static block.
static{
Timer t = new Timer();
//create a file at a period of time
}
This is in the servlet.
The servlet is going to run in 3 clusters.
I assume, this would cause the problem of creating 3 files instead of one.
Am I guessing right!. If so, what do you think is the solution?
Thanks,
Deepa :roll:
 
Kalyan Ayyagari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you first check to see if the file already exists. Don't create if it exists. (You have to make sure that access to the file is synchrinized this way.)
 
varnika Raman
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sound great. Unfortunately, that file is not saved at all.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a similar requirement, except that it is two cloned machines, not a cluster in our case. We had to have a separate client process external to the web app sending events to the cluster to periodically run the code. We didn't attempt it in the application itself.
(our external process makes an EJB call rather than a HTTP call, but the result is the same.)
Dave
 
Nijeesh Balan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
y don't u try synchronising the events with the db.
have a table in the db with m/c name as the column name
before writing go to the db and check to see if a m/c is already doing the file writing job. If so, skip it. If not, put an entry in the db.
Note: if u hv to update then do a select for update so that record is locked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!