aspose file tools*
The moose likes Servlets and the fly likes Startup Servlet in weblogic clustered environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Startup Servlet in weblogic clustered environment" Watch "Startup Servlet in weblogic clustered environment" New topic
Author

Startup Servlet in weblogic clustered environment

Prem Kashyap
Ranch Hand

Joined: Oct 10, 2006
Posts: 52
I have a startup servlet which creates a new thread to read a file and create some instance with the values fetched from the file.
The WAR file is deployed in weblogic clustered environment.
So the issue is that there are 2 clusters. And both the clusters are creating the thread and making new instance with same values from the file.
So i am having duplicate instances.

Is there any way I can stop the 2nd cluster from creating the thread if first cluster has created the thread?

How about having one config parameter in web.xml say for example: createThread and set its value to false when one of the cluster creates the thread.

Any suggestion will help...

Regards
Prem Kashyap
SCJP 1.4
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If it's clustered, I would think you would want two instances; one for each node.

Also, if you have a Servlet Spec 2.3 or higher container, why aren't you using a context listener instead of startup servlets?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prem Kashyap
Ranch Hand

Joined: Oct 10, 2006
Posts: 52
Basically, the code is a utility code that needs to create instance from a file and those instances are to be used in a different application. So i do not need duplicate instance when i open up that application.

I thought ServletContext listeners will also be invoked for each of the clusters. I am using 2.3 specification.

Thanks.. I am waiting for some more inputs before deciding on how to do it.

Regards
Prem Kashyap
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Prem Kashyap:
Basically, the code is a utility code that needs to create instance from a file and those instances are to be used in a different application. So i do not need duplicate instance when i open up that application.


Instance of what?
How does this other app use this instance and how are you passing it to the
other app?



I thought ServletContext listeners will also be invoked for each of the clusters. I am using 2.3 specification.


They will.
I wasn't suggesting that using them would solve this problem.
I was just curious as to why you were still using a startup servlet.
Prem Kashyap
Ranch Hand

Joined: Oct 10, 2006
Posts: 52
Instance of what?
How does this other app use this instance and how are you passing it to the
other app?

Hmm.. We need to create instance for BEA Aqualogic BPM Process. Its hard to explain you in full detail here. Its like a another application which is also deployed in same server as EAR . The instance we create are visible in the Aqualogic BPM application inbox. So double instance for same record of the excel file is getting created and visible in the inbox. The end user needs to work on that instance from the inbox. We need just one instance for a record in the excel file. The excel needs to be read once only. But both the clusters are reading the excel file and creating instances.

So just wondering, how to make it work. I was thinking of using a separate table . and checking a column value in that table before creating the new thread for instance creation. So if value is true, create the thread and make the value to false. So when 2nd cluster comes and checks the value , it will be false and it wont create the thread.

Or Can i use JMS to notify the 2nd cluster when the first cluster creates the thread.

I have one doubt : is there any chance that both the clusters will execute the start up servlet init code at exactly the same time.


I can use ServletContext Listeners, but the behaviour of that may vary with different application servers. So have not explored much in using context listener.

Thanks for the reply. if you get anything nice to solve this problem, then do let me know.

Regards
Prem Kashyap
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I don't know a lot about WebLogic or it's BPM processes but, if these are both on the same machine, couldn't you just create and check for a marker file from your startup servlet?

Node one checks for the marker file, doesn't find it so creates it, and then moves on to the startup procedure.
Node two checks for the file, finds it, cancels startup procedure, removes file.
Prem Kashyap
Ranch Hand

Joined: Oct 10, 2006
Posts: 52
Thanks.. Thats look like a great solution... I will try to implement this.

Thanks again..

Regards
Prem Kashyap
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Startup Servlet in weblogic clustered environment