Disruptor技术调研之配置ExceptionHandler

本文详细介绍了Disruptor框架中异常处理机制的多种配置方式,包括使用handleExceptionsWith及setDefaultExceptionHandler方法的区别,并展示了如何为特定事件处理器设置异常处理器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、举例:handleExceptionsWith设置

disruptor.handleExceptionsWith(exceptionHandler);
disruptor.handleEventsWith(handler);


2、举例:handleExceptionsWith方式设置需要在handler注册前设置

disruptor.handleExceptionsWith(exceptionHandler);
disruptor.handleEventsWith(handler);
disruptor.handleExceptionsWith(new FatalExceptionHandler());

注册handler时,通过获取Disruptor上下文中已经设置的exceptionHandler --->>

if (exceptionHandler != null)
{
    batchEventProcessor.setExceptionHandler(exceptionHandler);
}


3、举例:推荐使用setDefaultExceptionHandler方法设置exceptionHandler

disruptor.setDefaultExceptionHandler(exceptionHandler);
disruptor.handleEventsWith(handler);

--->>

private ExceptionHandler<? super T> exceptionHandler = new ExceptionHandlerWrapper<T>();

--->>

private ExceptionHandler<? super T> delegate = new FatalExceptionHandler();

public void switchTo(final ExceptionHandler<? super T> exceptionHandler)
{
    this.delegate = exceptionHandler;
}


4、举例:setDefaultExceptionHandler不同于handleExceptionsWith方法可以在handler注册后设置,原因是重新设置的exceptionHandler代理,见上述代码

disruptor.handleEventsWith(handler);
disruptor.setDefaultExceptionHandler(exceptionHandler);


5、举例:灵活设置

disruptor.handleEventsWith(eventHandler);

disruptor.handleExceptionsFor(eventHandler).with(exceptionHandler);

--->>

com.lmax.disruptor.dsl.ExceptionHandlerSetting<T>

A support class used as part of setting an exception handler for a specific event handler. For example:

disruptorWizard.handleExceptionsIn(eventHandler).with(exceptionHandler);
Type Parameters:
<T> the type of event being handled.

转载于:https://my.oschina.net/u/914290/blog/668597

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值