@PostConstruct在JBoss 7上使用@Singleton和@Startup在类中执行了两次

 手机用户2702939047 发布于 2023-02-02 19:50

我有以下课程:

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;
import javax.inject.Inject;

import com.mysite.Config;

@Startup
@Singleton
public class Scheduler {

    @Resource
    private TimerService timerService;

    @Inject @Config
    private Logger log;

    @Inject @Config
    private Integer delay;

    @Inject @Config
    private Integer interval;

    @Inject @Config
    private Boolean enabled;

    @PostConstruct
    public void initTimer() {
        if (enabled) {
            TimerConfig tc = new TimerConfig();
            tc.setPersistent(false);
            timerService.createIntervalTimer(delay, interval, tc);
        }
    }

    @Timeout
    public void timeout(Timer timer) {
        // do something
    }
}

包结构:

java的

数据加载器(这里是有问题的类)

其他包裹

资源

META-INF,配置等

在部署到JBoss 7.1.1时,此类的initTimer方法总是被调用两次,这会导致每次调用超时两次.

我已经从这里和这里知道它是JBoss中的一个错误(据说它固定在7.1.1但显然不是).我的问题是 - 有没有人知道我可以用来阻止@PostConstruct方法的双重执行的任何解决方法(我有更多这样的类,它们都有同样的问题)?

我已经看到了更多类似这样的问题,但它们都与一些REST库或Spring和CDI初始化bean连接两次 - 这不是这里的情况.

任何帮助表示感谢,谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有