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

标签 jakarta-ee jboss ejb jboss7.x scheduler

有人知道如何在 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/

相关文章:

java - @Schedule 注释每隔几分钟(或几秒钟)运行一次

jboss - WELD-001408 不满足的依赖关系

jakarta-ee - 参数拦截器在 Java EE 中不起作用

java - 是否可以在 JSP 中访问后端方法?

oracle - 无法在 Wildfly 10 上定义 oracle 数据源

maven - CXF InInterceptor 未触发

java - 在部署中找不到名为cinemaReservationPersistenceUnit的持久单元 "javakurs3.final.project.cinema.war"

java - 如何将数据从 EJB 拦截器传递到异步 EJB 中的拦截器

java - addShutDownHook 的内存泄漏

java - 尝试返回自定义对象类型时出现 SerializationException