使用 WebSphere Application Server 开发高性能 J2EE 线程
2009-09-30 00:00:00 来源:WEB开发网图片看不清楚?请点击这里查看原图(大图)。
用法示例:WASThreadFactory
要使用 WASThreadFactory,应用程序必须首先查找 Asynchronous Beans WorkManager,创建一个 WASThreadFactory 实例,然后构造新的线程池。下载文件示例中可提供使用 Servlet 的工作例子。
// Lookup the WorkManager and construct the WASThreadFactory
InitialContext ctx = new InitialContext();
WorkManager wm = (WorkManager)ctx.lookup("java:comp/env/wm/default");
ThreadFactory tf = new WASThreadFactory(wm);
// Create a ThreadPoolExecutor using a bounded buffer
BlockingQueue q = new ArrayBlockingQueue(10);
ThreadPoolExecutor pool = new ThreadPoolExecutor(
1, 10, 5000, TimeUnit.MILLISECONDS, q, tf);
// Use the submit or execute methods to submit work to the pool
pool.submit(myRunnable);
用法示例:ContextExecutor
使用带 ContextExecutor 的 WASThreadFactory 将可运行线程提交给带提交程序的 J2EE 上下文的自定义线程池与创建 ContextExecutor 实例一样简单。也可以使用 ContextExecutorService 来跟踪提交的任务的状态。
// Create a ThreadPoolExecutor
ThreadPoolExecutor pool = new ThreadPoolExecutor(
1, 10, 5000, TimeUnit.MILLISECONDS, q, tf);
// Wrap the ThreadPoolExecutor with a ContextExecutor
ContextExecutor cePool = new ContextExecutor(wm, pool);
// Use the ContextExecutor.execute() method to submit work to the pool.
cePool.execute(myRunnable)
Tags:使用 WebSphere Application
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接