在应用程序作用域bean上的postconstruct方法上创建Scheduler

时间:2015-04-18 11:58:37

标签: java scheduled-tasks cdi java-ee-7

在ApplicationScoped bean的PostConstruct方法上创建Scheduler作业是否有效。

@ApplicationScoped
public class myBean {

    private String name = "Soup of the day";

    @Schedule(hour="0", persistent=false)
    @PostConstruct
    public void afterCreate() {
        System.out.println("Bean Created");
    }

    public String getName() {
        return name;
    }

    public void setName(String name){
        this.name = name;
    }
}

1 个答案:

答案 0 :(得分:0)

具有@Singleton注释(在类上)和@Startup注释(在方法上)的@Schedule EJB应该足够了。您不需要使用@PostConstruct,因为这会强制您将Singleton EJB实例注入某些位置(根据您的使用情况,我假设这是不可能的)

相关问题