我正在寻找使用 dirsuptor 环形缓冲区来解析文件。但我看不到如何为环形缓冲区设置一个值范围。
在下面的示例中似乎。它循环到每个项目以将其分配给缓冲区。但是我,我想直接分配 x 项。
当我执行 FileInputStream.read( byte[] bytes ) 时,我想将这些字节放入环形缓冲区。
通常我的缓冲区比我读取的字节大两倍。像这样我可以在计算一个页面时读取另一页(例如字节数组长度==缓冲区/2):
ExecutorService exec = Executors.newCachedThreadPool();
// Preallocate RingBuffer with 1024 ValueEvents
Disruptor<ValueEvent> disruptor = new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, 1024, exec);
// Build dependency graph
RingBuffer<ValueEvent> ringBuffer = disruptor.start();
for (long i = 10; i < 2000; i++) {
String uuid = UUID.randomUUID().toString();
// Two phase commit. Grab one of the 1024 slots
long seq = ringBuffer.next();
ValueEvent valueEvent = ringBuffer.get(seq);
valueEvent.setValue(uuid);
ringBuffer.publish(seq);
}
谢谢