PayaraMicro不会在EJB或ApplicationScoped上调用@PreDestroy [英] PayaraMicro does not call @PreDestroy on EJB or ApplicationScoped

查看:93
本文介绍了PayaraMicro不会在EJB或ApplicationScoped上调用@PreDestroy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将WAR应用程序从PayaraServer迁移到Payara Micro,以减少RAM使用。

I'm migrating a WAR application from PayaraServer to Payara Micro to reduce RAM usage.

我只是意识到停止实例时不会调用EJB上的@PreDestroy

I just realise that @PreDestroy on EJBs are not called when stopping the instance with CTRL+C.

是否存在正确关闭payaramicro实例的正确方法,因为我想执行一些操作。

Is there a correct way to close the payaramicro instance properly as I'd like to execute some operations.

感谢您的回答!

还是要停用Payara Server中的哪些服务以使用与PayaraMicro一样多的RAM?

Or which services in Payara Server to deactivate to use as much as RAM as PayaraMicro?

我使用的是5.183版本,我也尝试了5.192版本。

I'm using the version 5.183, and I also tried the 5.192.

推荐答案

哪种使用过EJB?在我看来,它应该在 @Singleton @Stateless 上运行。我不确定Payara Micro如何支持其他EJB。

Which kind of EJB did you use? In my opinion it should work on @Singleton and @Stateless. I am not sure how the other EJBs are supported by Payara Micro.

但是,由于Payara Micro支持Java EE Web Profile,并且您无论如何都在使用Web应用程序,因此建议使用 @WebListener 来通知生命周期事件。

However, since Payara Micro supports the Java EE Web Profile and you are using a web application anyway, I would suggest to use a @WebListener to get notified of lifecycle events.

可以将其实现如下:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class ContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        // do needed setup work here
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        // do your cleanup actions here
    }
}

然后将此类添加到您的WAR文件中。

Simply add this class to your WAR file then.

这篇关于PayaraMicro不会在EJB或ApplicationScoped上调用@PreDestroy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆