如何限制Jersey Restful Web Services中在服务器端创建的线程数? [英] How to limit number of threads created on server side in Jersey Restful Web Services?

查看:107
本文介绍了如何限制Jersey Restful Web Services中在服务器端创建的线程数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jersey为每个请求创建一个线程. 是否可以限制在泽西岛服务器端创建的线程数 宁静的Web服务?

Jersey creates one thread per request. Is it possible to limit number of threads created on server side in Jersey Restful Web Services?

首先,我创建了一个包含4种方法的资源,即创建,更新,删除, 读取以对数据库执行操作.

Firstly, i created a resource containing 4 methods viz., create, update, delete, read to perform operations on database.

然后我写了一个shell脚本,它异步创建10个进程,每个进程 执行100组(1组= Create()+ Update()+ delete()+ read())的CURD操作 使用不是异步的cURL请求,因为我必须计算总时间 为每个cURL请求所采用.

Then i wrote a shell script which creates 10 process asynchronously and each process performs 100 sets(1 set = Create() + Update()+ delete() + read()) of CURD operations using cURL requests which were not asynchronous as i had to calculate total time taken for each cURL request.

我得到的结果是:

Total time taken by 10 processes to complete is: 989.733 seconds
Average time of 10 processes is: 98.97330 seconds

当我将CURD集的数量增加到4000时,它失败了. 然后,我在Jersey REST中创建了一个包含异步方法getData()的资源. 以获得更好的性能. 现在,我打算限制在Jersey REST的服务器端创建的线程数 不论从客户端发出的请求数量如何. 是否有可能? 预先感谢.

When i increased the number of CURD sets to 4000, it failed. Then, i have created a resource which contains async method getData() in Jersey REST for better performance. Now, i intend to limit the number of threads created on server side in Jersey REST irrespective of number of requests fired from client side. Is it possible? Thanks in advance.

推荐答案

详细信息将完全取决于您如何部署服务.

The details will depend on exactly how you are deploying your service.

例如, Jersey docs 描述部署到各种不同的servlet容器.这意味着从服务器的角度来看,线程是由容器处理的,因此它是您需要配置的容器.

As an example, the Jersey docs describe deploying to various different servlet containers. This implies that from the server's perspective the threading is handled by the container and so it's the container you need to configure.

每个servlet容器都有定义的方式来执行此操作:例如

Each servlet container will have a defined way of doing this: For example GlassFish

这篇关于如何限制Jersey Restful Web Services中在服务器端创建的线程数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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