简体   繁体   中英

How to make J2EE weblogic application resilient to database problems

I have a Web application running on Oracle Weblogic Server 11g . It uses a datasource defined in the application server to connect to the Oracle Database (11g too), its class is

oracle.jdbc.xa.client.OracleXADataSource

  • If for some reason the database becomes not present and then comes backs, the application is running ok (it gets exceptions while trying to access the db but this is fine and then can again get some new connections when the db comes back)

  • However, if the database is down during weblogic server startup , the datasource is not deployed on the server and the application throws an exception because it has not any datasource available, the deployment is marked as failed and of course nothing does repair this automatically.

Is there a way to make the datasource be deployed even if the database is not present during server startup ? (such that the application becomes usable when the database is back)

Why do you want to deploy an application without a valid datasource?

You could possibly fake the datasource (create a dummy datasource with the same JNDI name) and assuming that the application does not validate datasource schema at startup you will get a semi-functional running application (which will fail with the first DB interaction).

When the real datasource is up and running you won't be able to switch to it. You will still have to restart the application server.

Update:

According to the J2EE spec (1.5 version) resources are binded during the deployment process. I believe that it is possible to implement a custom Factory that will return dummy / active datasource. Does it worth the effort to implement? ;)

EE.5.6.2 Deployer's Responsibilities

Bind the resource manager connection factory reference to a resource manager connection factory that exists in the operational environment. The Deployer may use, for example, the JNDI LinkRef mechanism to create a symbolic link to the actual JNDI name of the resource manager connection factory. The re- source manager connection factory type must be compatible with the type de- clared in the res-type element.

The option you are looking for is "Connection Creation Retries", check this link

"If set and if the database is unavailable when the data source is created, WebLogic Server attempts to create connections in the pool again after the number of seconds you specify, and will continue to attempt to create the connections until it succeeds. This option applies to connections created when the data source is created at server startup ..."

将“初始容量”设置为http://docs.oracle.com/cd/E14571_01/web.1111/e13814/jdbc_tuning.htm#i1028616 :启动时的weblogic不会尝试创建任何连接,并且如果数据库不可用。

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