poisonbean.java

来自「EJB3.0请一定要上载质量高而且本站没有的源码」· Java 代码 · 共 40 行

JAVA
40
字号
package examples.messaging;

import javax.jms.*;
import javax.ejb.*;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

@MessageDriven(activationConfig = 
{ @ActivationConfigProperty(propertyName = "destinationType", 
        propertyValue = "javax.jms.Topic") })
public class PoisonBean implements MessageListener {

    @Resource
    private MessageDrivenContext ctx;

    public PoisonBean() {
        System.out.println("PoisonBean created");
    }

    public void onMessage(Message msg) {
        try {
            System.out.println("Received msg " + msg.getJMSMessageID());

            // Let抯 sleep a little bit so that we don抰
            // see rapid fire re-sends of the message.
            Thread.sleep(3000);

            // We could either throw a system exception here or
            // manually force a rollback of the transaction.
            ctx.setRollbackOnly();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @PreDestroy
    public void remove() {
        System.out.println("PoisonBean destroyed.");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?