运行Web服务请求的线程池的线程数合理 [英] Reasonable number of threads for thread pool running web service requests

查看:236
本文介绍了运行Web服务请求的线程池的线程数合理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中创建FixedThreadPool Executor对象时,您需要传递一个参数,描述执行程序可以并发执行的线程数。我建立一个服务类,负责处理大量的电话号码集合。对于每个电话号码,我需要执行Web服务(这是我的瓶颈),然后在hashmap中保存响应。

When creating an FixedThreadPool Executor object in Java you need to pass an argument describing the number of threads that the Executor can execute concurrently. I'm building a service class that's responsibility is to process a large collections of phone numbers. For each phone number I need to execute web service (that's my bottleneck) and then save response in a hashmap.

为了使这个瓶颈对我的服务性能的影响更小我决定创建Worker类,它获取未处理的元素并处理它们。 Worker类实现了Runnable接口,我使用Executor来运行Workers。

To make this bottleneck less harmful to the performance of my service I've decided to create Worker class which fetches unprocessed elements and processes them. Worker class implements Runnable interface and I run Workers using Executor.

可以同时运行的Worker数量取决于Executor FixedThreadPool的大小。 ThreadPool的安全大小是多少?

The number of Workers that can be run in the same time depends on the size of Executor FixedThreadPool. What is the safe size for a ThreadPool? What can happen when I create FixedTheradPool with some big number as an argument?

推荐答案

如果每个工作线程需要创建一个web服务调用,那么池中的线程数应该受到Web服务可以处理的并发请求数的强烈影响。任何比这更多的线程只会淹没Web服务。

If each worker thread needs to make a web service call, then the number of threads in your pool should be influenced strongly by how many simultaneous requests your web service can handle. Any more threads than that will do nothing more than overwhelm the web service.

这篇关于运行Web服务请求的线程池的线程数合理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆