Virtual Thread not perform right when use with Disruptor workPool in openjdk19
地上的月影
404450559 at qq.com
Thu Aug 4 07:58:23 UTC 2022
Hi All
I'm one of openjdk user and these days I tried to use the preview feature Virtual Thread with Disruptor. when use ThreadFactory in Disruptor workerPool, somingthing seems wrong that when I used Thread.ofVirtual().start. the new created virtualThread seems don't start? it don't print hello world, I'm not sure whether it's a bug or I use it wrong, here are my core test code
public void test2() throws InterruptedException {
System.out.println( "Start Test!" );
RingBuffer<Order> ringBuffer = RingBuffer.create(ProducerType.MULTI, new EventFactory<Order>() {
@Override
public Order newInstance() {
return new Order();
}
}, 1024 * 1024, new YieldingWaitStrategy());
SequenceBarrier barrier = ringBuffer.newBarrier();
Consumer[] consumers= new Consumer[10];
for (int i = 0; i < consumers.length; i++) {
consumers[i] = new Consumer("C"+i);
}
WorkerPool<Order> workerPool = new WorkerPool<>(ringBuffer, barrier, new EventExceptionHandle(), consumers);
ringBuffer.addGatingSequences(workerPool.getWorkerSequences());
ThreadFactory factory_v = Thread.ofVirtual().factory();
ExecutorService pool = Executors.newFixedThreadPool(10, factory_v);
workerPool.start(pool);
// don't print hello world?
Thread thd = Thread.ofVirtual().start(() -> System.out.println("Hello world!"));
Thread.sleep(5000);
System.out.println("End Test!" );
}
looking forward to your answers.
best wishes!
-Anjian Wen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20220804/3e303edb/attachment-0001.htm>
More information about the loom-dev
mailing list