Weblogic +达蒙线程
希望有人能够帮助我找到启动后台线程来监视我的数据库连接的解决方案。我们的应用程序部署在 weblogic 92 中,我想知道是否有办法在应用程序运行时启动线程运行?谢谢,
我正在尝试监视我的数据库,以确保在连接失败时我可以切换数据库。因此,我正在寻找一种简单的解决方案来运行后台任务。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管在许多应用程序服务器中您可以,但您不应该在 Java EE 服务器中创建自己的线程,请参阅 为什么不鼓励在 Java EE 容器中生成线程? 了解一些背景信息和解决方法。
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.
根据您要检查的条件以及要采取的操作,您可以使用 WebLogic 诊断框架。您可以让它在检测到特定条件时发送 JMS 消息,然后您可以使用 MDB 执行任何您想要的操作。
用条件和条件更新您的问题您想要采取的行动,我可以提供更多详细信息。
一般来说,启动您自己的线程是不可取的。
更新:
根据您的描述,我猜测您不使用 JNDI 或 WebLogic 数据源。如果使用WebLogic中的数据源进行连接池会更好。 WebLogic 可以检测到池中的连接损坏并在将其提供给应用程序之前重新创建它。
如果您引用不同的数据库,那么 WebLogic 有一个具有故障转移功能的多数据源选项。您应该做的是配置两个数据源 - 一个主数据源和一个辅助数据源 - 然后创建一个多数据源来包装它们。然后,您应该在应用程序中使用多数据源的 JNDI。显然,如果您这样做,您需要确保两个数据库实例之间的数据一致。
这不会使您的应用程序特定于 WebLogic,因为它只是对 JNDI 名称的更改。 WebLogic 负责剩下的事情。
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.