简体   繁体   中英

Run task at start of disruptor handler thread

I am using the LMAX disruptor and it works really well.

I would like to execute some core affinity code (that needs to run ON THE DISRUPTOR HANDLER's THREAD), at the begginning of the disruptor's thread lifecycle.

I tried overriding the start method in the disruptor, but this code still runs on the executing thread and not the disruptor thread, something like this:

ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("DisruptorThread").build();
Disruptor<OrderBasedEventHolder> disruptor = new Disruptor<>(new Disruptor<Holder> disruptor = new Disruptor<Holder>(new HolderFactory(), (int) Math.pow(2, bufferExp), factory, pType, waitStrategy) {
        @Override public RingBuffer<OrderBasedEventHolder> start() {
            // Initialization code

            return super.start();
        }
    };
disruptor.start();

How can override the run() method of the thread created by the ThreadFactory?

Thanks!!!

I have solved this before by enqueing an inital entry (with a special type) before any other entries and adding handling code for this initial "start" entry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM