简体   繁体   中英

how to make a code run once on the cluster during the server startup and will also work on non cluster environment

Background: What I need is a way to subscribe to the external system only once during the server startup on clustered environment. So far we were using ApplicationLifecycleListener to run the subscription. In our code we were trying to find a winner node to make the subscription but for some reason it does not work and all 4 are sending their request. (the code was written on Weblogic 8.1) Now after we've migrated to the weblogic 11g I've found a SingletonService that did the trick. Unfortunately we cannot use it as when we develop our application locally we test it on non-cluster environment and Singleton Service does not work on it.

My question: Is there a way to register SingletonService after the application is started and we, eg. in ApplicationLifecycleListener discover that we are on the cluster? If not, do you have any suggestions on how to solve our problem?

Can you use a startup class and only target it to one machine instead of all 4? You will need to add the startup class to the server's classpath. You can view startup/shutdown classes in the weblogic console under "Environment".

Here is a brief example: http://buttso.blogspot.com/2009/09/weblogic-server-startup-and-shutdown.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM