配置通过 CXF 以编程方式启动的码头

Configure jetty that is launched via CXF programmatically

我在使用 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 启动它时以编程方式配置 jetty 线程池 minThreads 和 maxThreads 的大小?

你在这里:

    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 测试