quartz如何启动EJB无状态组件?
我正在使用 Jboss5.1.x,EJB3.0
我已经研究这个主题几天了。我听说这应该很容易,但似乎要么缺少文件,要么我很难得到一些东西。
我的场景是有一个计划任务,当我第一次将我的应用程序服务器项目部署到 jboss 时,该任务将触发,然后我希望我的进程每 X 次重新执行一次。
我终于成功地将quartz mbean添加到jboss-service.xml中,
但是:
如何在服务器部署后自动触发它?我看到我必须通过servlet 来完成?那么我将如何在项目部署时触发 servlet?我不能在没有 servlet 的情况下直接在 EJB bean 上触发它吗?
触发后,我想从触发方法调用EJB无状态bean。
我希望场景是这样的:(
应用程序部署 -> Quartz -> EJB bean -> ..) insteadof (应用程序部署 -> Quartz -> servlet -> EJB bean)
我该怎么做?这是我找到的代码:
InitialContext ctx = new InitialContext();
StdScheduler scheduler = (StdScheduler) ctx.lookup("Quartz");
JobDetail jd = new JobDetail("myjob", scheduler.DEFAULT_GROUP, NewJob.class);
CronTrigger ct = new CronTrigger("cronTrigger", "group2", "0 0/5 * * * ?");
scheduler.scheduleJob(jd, ct);
看来通过这段代码它只会触发POJO(“NewJob.class”)。我想触发 EJB 无状态 bean。
有人有答案吗?请..最坏的情况我会从石英切换到其他东西。
谢谢, 射线。
I am using Jboss5.1.x, EJB3.0
I am into this subject for couple of days now. I heard it suppose to be easy, but it seems that or it's lack of documents or it was hard for me to get some things.
My scenario is to have a scheduled task which will trigger when I first deploy my application server project to jboss and then I want my proccess to re-executed every X time.
I have finally managed to add the quartz mbean to jboss-service.xml
but:
how do I trigger it after server deployment automaticly? I saw I must do it through servlet? so how will I trigger the servlet on project deploy? cant I trigger it without a servlet and do it straightly on EJB bean?
after it being trigger, I want to call from the trigger method to an EJB stateless bean.
i would want the scenario to be something like this:
(application deploy -> Quartz -> EJB bean -> ..) insteadof (application deploy - > Quartz -> servlet -> EJB bean)
how would I do that? this is the code I found:
InitialContext ctx = new InitialContext();
StdScheduler scheduler = (StdScheduler) ctx.lookup("Quartz");
JobDetail jd = new JobDetail("myjob", scheduler.DEFAULT_GROUP, NewJob.class);
CronTrigger ct = new CronTrigger("cronTrigger", "group2", "0 0/5 * * * ?");
scheduler.scheduleJob(jd, ct);
it seems that by this code it only triggers POJO's ("NewJob.class"). and I want to trigger EJB stateless bean.
anyone has any answers? please.. worst case I will switch from Quartz to something else.
thanks,
ray.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全理解你的问题 - 或者更确切地说,我猜测这里有多个问题,但我不太明白它的语言,因为你似乎使用“触发”这个词(一种石英术语) )以不止一种方式。
无论如何,我可以清楚地理解和回答您的一个问题,那就是如何让quartz 调用您的EJB 上的方法。只需编写一个 Job 类,在其execute() 方法中包含知道如何查找和调用该EJB 的代码。然后是该作业的调度程序和实例,每当它触发时,它都会调用 EJB。 Quartz 实际上附带了一个 EJBInvokerJob 来执行此操作,因此您可能无需修改即可使用它,或者可能希望使用其源代码作为起点。 (请注意,Jobquartz 附带调用 EJB v.2 bean。但是,有一个可用于调用 EJB3 bean 的类,您可以在此处下载:http://jira.opensymphony.com/browse/QUARTZ-732)
您需要重述的有关 mbean 和 servlet 的其他问题,因为它让我感到困惑为什么您会这样做使用这两种机制。
I don't fully understand your question - or rather I am guessing that there is more than one question here, but I don't quite follow the language of it, as you seem to be using the word "trigger" (a quartz term) in more than one way.
At any rate, there is one of your questions that I can clearly understand and answer, and that is how to get quartz to invoke a method on your EJB. Simply write a Job class that contains code in its execute() method that knows how to lookup and invoke that EJB. Then scheduler and instance of that job, and whenever it fires it will invoke the EJB. Quartz actually ships with an EJBInvokerJob that does just that, so you may be able to use it without modification, or may want to use its source code as your starting point. (Note that the Job quartz ships with invokes EJB v.2 beans. However, there is class available for invoking EJB3 beans, which you can download here: http://jira.opensymphony.com/browse/QUARTZ-732)
Your other question about the mbean and servlet you need to restate, as it confuses me why you would be using both mechanisms.