0

JBoss EAP 6.2.4 を使用しており、ステートレス セッション Bean 内で JMS メッセージを WMQ-queuemanager に送信します。

私たちのコードは次のとおりです。

@Stateless
@LocalBean
public class MessageSenderBean {

    private static ConnectionFactory connectionFactory;
    private static InitialContext initialContext;

    @EJB
    IntegrationPropertyBean ipb;

    Logger logger = Logger.getLogger(getClass());

    /**
     * Default constructor.
     */
    public MessageSenderBean() {

    }

    @PostConstruct
    public void postConstruct() {
        logger.debug(" MessageSenderBeanPostConstruct called");
        try {
            initialContext = new InitialContext();
            String connectionFactoryName = ipb.getProperty(
                    MessageSenderBean.class, "connectionFactory");
            connectionFactory = (ConnectionFactory) initialContext
                    .lookup(connectionFactoryName);

        } catch (NamingException e) {
            logger.error("Exception occurred: " + e.toString());
            logger.error(e);
        }

    }

    public String sendMessage(String queueName, String content) {
        String result = null;
        Connection connection = null;
        try {
            connection = connectionFactory.createConnection();
        } catch (JMSException e) {
            logger.error("Exception occurred: " + e.toString());
            logger.error(e);
        }

        // prüfen ob InitialContext leer
        try {
            if (initialContext == null)
                initialContext = new InitialContext();
        } catch (NamingException e) {
            logger.error("Exception occurred: " + e.toString());
            logger.error(e);
        }

サーバーの起動後、Bean は最初のアクションに対しては完全に機能しますが、アクションがない状態でしばらくすると、Bean は initialContext を失い、新しい InitialContext() 内で追加の作成が失敗します。

理由はありますか?

ありがとうヨルグ

4

1 に答える 1