我从jetlang开始,基本示例非常清晰。我没有找到使用 PoolFiber 的好示例。有人玩过吗?我还阅读了 retlang 示例,但那里似乎有点不同。
感谢您分享您的想法!
大神
使用 PoolFiber 和 ThreadFiber 几乎相同。唯一的区别是线程池需要初始化并用于创建每个 PoolFiber。
// create java thread pool.
ExecutorService pool = Executors.newCachedThreadPool();
//initialize factory with backing pool
PoolFiberFactory fiberFactory = new PoolFiberFactory(pool);
Fiber fiber = fiberFactory.create();
fiber.start();
//use fiber for normal publishing and subscribing.
这是在 Github 上。
https://github.com/jetlang/jetlang/blob/readme/src/test/java/org/jetlang/examples/BasicExamples.java
这是 mvn 网站 http://jetlang.github.io/jetlang/
int availableProcessors = Runtime.getRuntime().availableProcessors();
int threadPoolSize = availableProcessors*2;
ThreadPoolExecutor POOL = new ThreadPoolExecutor(threadPoolSize,
threadPoolSize, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
PoolFiberFactory fiberFactory = new PoolFiberFactory(POOL);