disruptor部分代码流程控制使用的是异常,抛出自定义的异常,外层捕捉,下面是它封装的异常
直接贴代码:
public final class AlertException extends Exception
{
/**
* Pre-allocated exception to avoid garbage generation
*/
public static final AlertException INSTANCE = new AlertException();
/**
* Private constructor so only a single instance exists.
*/
private AlertException()
{
}
/**
* Overridden so the stack trace is not filled in for this exception for performance reasons.
*
* @return this instance.
*/
@Override
public Throwable fillInStackTrace()
{
return this;
}
}
这次用来控制消费者线程的异常,控制消费者究竟什么时候停下来;fillInStackTrace方法是为了把同步改成异步填充异常堆栈信息;感觉这里比较新鲜的是搞了个INSTANCE静态变量,不需要每次都要new异常对象,以前自己封装异常的时候自己没这样用过,感觉还是挺新鲜的