Configure jetty that is launched via CXF programmatically
Asked Answered
K

1

7

I launch a jetty instance indirectly when creating a JAX-RS endpoint using cxf

    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(HelloWorldResource.class);
    sf.setResourceProvider(HelloWorldResource.class, new SingletonResourceProvider(new HelloWorldResource()));
    sf.setAddress("http://localhost:9000/");
    sf.create();

This works just fine, but how can i configure the size of the jetty threadpool minThreads and maxThreads programmatically when launching it via CXF?

Kirtley answered 2/5, 2019 at 9:34 Comment(0)
C
2

here you are:

    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();

According to my tests, at least 4 threads should be specified.

Tested with CXF 3.3.3

Cordless answered 1/10, 2019 at 12:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.