Jetlang PoolFiber样本

时间:2008-11-13 12:55:59

标签: java concurrency

我从jetlang开始,基本样本非常清楚。 我没有找到的是使用PoolFiber的好样本。有人玩过 那已经?我也阅读了retlang样本,但它似乎有点不同。

感谢您分享您的想法!

3 个答案:

答案 0 :(得分:5)

使用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.

答案 1 :(得分:0)

答案 2 :(得分:0)

比Cache更好的池,涉及与JVM相关的CPU核心数量:

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);