java - 如何在 newfixedthreadpool 中获得更高的性能?

标签 java threadpool

我的英语不好。但我需要了解 newfixedthreadpool 的 .

enter code here
ExecutorService executorService = new FixedThreadPool().newFixedThreadPool(4);
.....
public class FixedThreadPool {
        private ExecutorService newFixedThreadPool(int nThreads) {   
            return new ThreadPoolExecutor(nThreads, nThreads,   
                    0L, TimeUnit.MILLISECONDS,   
                    new LinkedBlockingQueue<Runnable>());   
        }

}
.....
executorService.execute(new CoreThreadPool(list, resCountClass));

当zip文件解压缩时,每个入口文件都会在这些线程池中执行和加密。 [ 解压缩 -> 加密(池) -> zip ]

当我在 eclipse 中进行 UNIT 测试(仅解压缩->加密->zip)时,它针对顺序处理(我的旧项目)显示出良好的性能(高出 30%)。 但是在Jboss中部署该项目后,部分(unzip->加密->zip)的性能表现出稍微好一些(5%)或与顺序处理相同。有时会更低。 *在 Linux 和 Windows 上测试

我想知道为什么结果会这样。我需要解决它.. 我可以将队列 LinkedBlockingQueue 更改为另一个吗? 任务线程可以异步运行吗?

请给出答案或提示..

干杯,伙计!!!

最佳答案

很可能您正在最大限度地使用共享资源,例如读写磁盘或三级缓存的速度。这些事情会阻止您有效地使用更多 CPU。为了解决这个问题,你必须找出你的瓶颈是什么。

关于java - 如何在 newfixedthreadpool 中获得更高的性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14700352/

相关文章:

multithreading - 多少线程太多了?

Java 线程 - 奇怪的 Thread.interrupted() 和 future.cancel(true) 行为

multithreading - 在Perl中使用多线程时,应如何更新哈希哈希?

java - YouTube 上传错误 - 上传失败 : Can't process file

java - RSA加密问题

java - WebDriverWait 不工作

java - 为什么在 Java 中清除值时我们得到一个空映射?

Java 可调用 : What happens to the thread before get() is called

c# - ThreadPool 在短短几秒钟内使用了过多的内存

java - 无法使用 curl 访问在 Eclipse 中创建的 Web 应用程序