背景线程 [英] Background threads

查看:215
本文介绍了背景线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Websphere Application Server创建一个典型的Web应用程序,其中UI是JSP,有一个Controller,一个会话EJB和一个数据库。我实现了一个通知系统,它作为一个单独的线程在后台运行。我为此目的使用了WorkManager。

I am using Websphere Application Server to create a typical web application where UI is JSPs, there is a Controller and a session EJB and a Database. I implemented a notification system which runs in the backround as a separate thread. I used WorkManager for that purpose.

我的问题是,我想启动WorkManager,而不必为不同用户启动的每个并行会话创建会话或EJB实例。它不应该是基于会话的。
现在,在实例化EJB时,WorkManager线程启动,因此如果有3个连接,则有3个WorkManager实例。

My problem is, I want to start the WorkManager without having to create a session or an EJB instance for every single of the parallel sessions started by different users. It should not be session based. Right now, the WorkManager thread kicks off when the EJB is instantiated, so if there are 3 connections, there are 3 WorkManager instances.

单身会话bean是个好主意吗?或者在某个地方我可以使用'main()'方法调用,或类似的东西?

Would singleton session bean be a good idea? or is there somewhere I can put a 'main()' method which will be called, or something similar?

任何想法都会受到赞赏。

Any ideas would be appreciated.

推荐答案

我认为你有几种选择:


  • 使用servlet上下文侦听器(在WAR模块启动/停止时调用)提交工作。

  • 使用启动Bean(WebSphere特定API)在启动/停止应用程序时调用一次。

  • 使用引用计数方法来跟踪EJB实例的数量。您在创建第一个实例时提交工作(并在销毁最后一个实例时将其停止)。请注意,这将延迟工作的开始,直到第一次向EJB发出请求为止。

  • 在WebSphere 8(支持Java EE 6)中,您可能使用单例会话bean。

  • Submit the work using a servlet context listener (which will be invoked when the WAR module is started/stopped).
  • Use a startup bean (WebSphere specific API) which is invoked once when the application is started/stopped.
  • Use a reference counting approach where you keep track of the number of EJB instances. You submit the work when the first instance is created (and stop it when the last instance is destroyed). Note that this will delay the start of the work until the first request to the EJB is made.
  • In WebSphere 8 (which supports Java EE 6) you could probably use a singleton session bean.

这篇关于背景线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆