`
sunlujing
  • 浏览: 178082 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

restlet 设置component的线程响应数

阅读更多
restlet 在实现web service 时相对简单,一个jar程序就可以发布服务。在我的毕设中的web service 程序就是使用 restlet 来发布的。 restlet默认的支持的线程最大响应数貌似只有20。发了一天的时间才找到如何设置默认的请求响应数。 在使用 50个线程并发运行时,抛出错误的类在 BaseHelper,源码中有描述: /** * Base connector helper. Here is the list of parameters that are supported. * They should be set in the connector's context before it is started: * * * Parameter name * Value type * Default value * Description * * * controllerDaemon * boolean * true * Indicates if the controller thread should be a daemon (not blocking JVM * exit). * * * controllerSleepTimeMs * int * 100 * Time for the controller thread to sleep between each control. * * * inboundBufferSize * int * {@link IoUtils#BUFFER_SIZE} * The size of the buffer when reading messages. * * * minThreads * int * 1 * Minimum threads waiting to service requests. * * * maxThreads * int * 10 * Maximum threads that will service requests. * * * maxConnectionsPerHost * int * -1 * Maximum number of concurrent connections per host (IP address). * * * maxTotalConnections * int * -1 * Maximum number of concurrent connections in total. * * * outboundBufferSize * int * {@link IoUtils#BUFFER_SIZE} * The size of the buffer when writing messages. * * * persistingConnections * boolean * true * Indicates if connections should be kept alive after a call. * * * pipeliningConnections * boolean * false * Indicates if pipelining connections are supported. * * * threadMaxIdleTimeMs * int * 60000 * Time for an idle thread to wait for an operation before being collected. * * * tracing * boolean * false * Indicates if all messages should be printed on the standard console. * * * * @author Jerome Louvel */ 这是设置component 响应性能的根本,就是要在创建connector时设置context 在restlet中 Server 对象继承connector 对象并与component关联。因此设置 连接数的代码如下: try { Component component = new Component(); Context context = new Context(); context.getParameters().set("maxThreads", "100"); context.getParameters().set("maxConnectionsPerHost", "100"); context.getParameters().set("maxTotalConnections", "100"); Server server = new Server(context,Protocol.HTTP, 8182); component.getServers().add(server); ApplicationController application = new ApplicationController(); component.getDefaultHost().attachDefault(application); component.start(); } catch (Exception e) { e.printStackTrace(); }
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics