gpt4 book ai didi

jakarta-ee - JBoss AS 7.1 - 使用 @Schedule 注释运行计划

转载 作者:行者123 更新时间:2023-12-04 14:04:05 24 4
gpt4 key购买 nike

有人知道如何在 JBoss AS 7 上使用 @Schedule 注释吗?

我知道在 Glassfish-3.1.2 上它是开箱即用的。

我试试这个:

@ManagedBean
@Stateless(name="ImportStatementSchedule")
public class ImportStatementSchedule implements Serializable{
private Logger _log = Logger.getLogger(this.getClass());

@Schedule(minute="*")
public void executeImport(){
_log.info("Scheduled task started");
}

}

我希望每分钟收到日志消息,但什么都没有;)

我检查了这些论坛主题,但没有任何帮助:

https://community.jboss.org/message/623574

https://community.jboss.org/message/621893

https://community.jboss.org/message/637567

有 JBoss AS 7.1.1-Final

也许我忘记了一些东西,请有人能指点我正确的方法吗?

更新:

我知道 JBoss 将我的 EJB 注册到 JNDI :
11:07:05,548 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-6) JNDI bindings for session bean named ImportStatementSchedule in deployment unit deployment "finadv.war" are as follows:

java:global/finadv/ImportStatementSchedule!finadv.bean.ImportStatementSchedule
java:app/finadv/ImportStatementSchedule!finadv.bean.ImportStatementSchedule
java:module/ImportStatementSchedule!finadv.bean.ImportStatementSchedule
java:global/finadv/ImportStatementSchedule
java:app/finadv/ImportStatementSchedule
java:module/ImportStatementSchedule

更新2

如评论中所述,已解决

最佳答案

定时器服务是 EJB 服务。 ImportStatementSchedule应该是 @Stateless@Singleton session bean。来自 EJB 3.1 规范的第 18.2 节:

For automatically created timers, the timeout method may be a method that is annotated with the Schedule annotation. Timers can be created for stateless session beans, singleton session beans, mes- sage-driven beans, and 2.1 entity beans. Timers cannot be created for stateful session beans.


INFO log 语句具有误导性。 JBoss 不注册 EJB。它只是使用与 @ManagedBean 定义的相同的命名方案。注释(Javadoc):

[..] Managed Bean names must be unique within a Java EE module. For each named Managed Bean, Java EE containers must make available the following entries in JNDI, using the same naming scheme used for EJB components. In the application namespace:

java:app/<module-name>/<bean-name>

In the module namespace of the module containing the Managed Bean:

java:module/<bean-name>

关于jakarta-ee - JBoss AS 7.1 - 使用 @Schedule 注释运行计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10395597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com