使用cxf创建JAX-RS端点时,我间接启动了一个码头实例
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(HelloWorldResource.class);
sf.setResourceProvider(HelloWorldResource.class, new SingletonResourceProvider(new HelloWorldResource()));
sf.setAddress("http://localhost:9000/");
sf.create();
这很好,但是当通过CXF启动码头线程池minThreads和maxThreads时,我该如何以编程方式配置它的大小?
答案 0 :(得分:2)
您在这里:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
// you need to provide a default configuration
JettyHTTPServerEngineFactory serverEngineFactory = sf.getBus().getExtension(JettyHTTPServerEngineFactory.class);
JettyHTTPServerEngine eng = new JettyHTTPServerEngine();
eng.setPort(0); // with the port zero
ThreadingParameters defaultThreadingParams = new ThreadingParameters();
defaultThreadingParams.setMinThreads(5);
defaultThreadingParams.setMaxThreads(10);
defaultThreadingParams.setThreadNamePrefix("myjetty");
eng.setThreadingParameters(defaultThreadingParams);
serverEngineFactory.setEnginesList(Arrays.asList(eng));
sf.setResourceProvider(HelloWorldResource.class, new SingletonResourceProvider(new HelloWorldResource()));
sf.setAddress("http://localhost:9000/");
sf.create();
根据我的测试,应该至少指定4个线程。
使用CXF 3.3.3测试