0

Hoping someone may be able to help me with a solution as to starting a background thread to monitor my database connection. Our application is deployed in weblogic 92 and I wondered if there was a way to start a thread running when the application is running ? thanks

I'm attempting to monitor my database to ensure I can switch databases should my connection fail. For this reason, I'm looking for an easy solution to run a background task.

user815809
  • 351
  • 5
  • 24

2 Answers2

1

Even though in many applications servers you can, you're not supposed to create your own threads in a Java EE server, see Why is spawning threads in Java EE container discouraged? for some background and workarounds.

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79
  • thanks @fvu. I know this but without linking my code directly to Weblogic, I'd hoped this was possible. I'm attempting to monitor my database to ensure I can switch databases should my connection fail. For this reason, I'm looking for an easy solution to run a background task. – user815809 Aug 21 '11 at 15:00
0

Depending on what condition you want to check for and what action you want to take you can use the WebLogic Diagnostic Framework. You could have it send a JMS message when it detects a certain condition and then you can do whatever you want with an MDB.

Update your question with the condition & action you want to take and I can provide more details.

Generally speaking, starting your own threads isn't advisable.

UPDATE: By your description I'm guessing you don't use JNDI or WebLogic datasources. It would be better if you used the datasources in WebLogic for connection pooling. WebLogic can detect that a connection in the pool is bad and recreate it before giving it to your application.

If you are referring to different databases then WebLogic has a multi-datasource option which has failover capability. What you should do is configure two datasources - one primary and one secondary - and then create a multi-datasource to wrap them. You then should use the JNDI of the multi-datasource in your application. Obviously if you do this you need to make sure the data is consistent between the two DB instances.

This does not make your application WebLogic-specific since it would just be a change to a JNDI name. WebLogic takes care of the rest.

Jeff West
  • 1,563
  • 9
  • 11