websphere中的多线程

Multithreading in websphere

我有一个多线程应用程序,所以我实现了 ExecutorService 池大小为 5 个线程

public class SimpleThreadPool {    
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 10; i++) {
          Runnable worker = new WorkerThread("" + i);
          executor.execute(worker);
        }
        executor.shutdown();
        while (!executor.isTerminated()) {
        }
        System.out.println("Finished all threads");
    }
}

应用程序将部署在 Websphere Web 服务器中,设置包含线程池配置:应用程序服务器 > > 线程池 > 默认值,最大大小设置为 60。

我的问题是,采用哪种池大小配置,Websphere 中的配置是否会覆盖代码中的配置(5 个线程)?

不,那些将是不同的线程池。

60线程的需要通过jndi服务按名称获取。 Websphere 线程池有点不同。例如,它支持 JTA(分布式)事务。您只能在那些特殊的线程池中使用 JTA 事务。

本地有5个线程,不受Websphere影响。您可以通过提交大量任务然后通过 jstackkill -3 命令打印线程堆栈来检查线程数。

这两件事没有任何关系。

server 设置是关于服务器使用的线程。见 documentation:

Use this page to configure a group of threads that an application server uses. Requests are sent to the server through any of the HTTP transports. A thread pool enables components of the server to reuse threads to eliminate the need to create new threads at run time. Creating new threads expends time and resources.

现在,您的应用程序代码创建了自己的独立线程池。

这与该系统池没有任何关系

当然,您的应用程序可以将 "tasks" 发送到该系统线程池;以这种方式使用它。