Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure jetty that is launched via CXF programmatically

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?

like image 660
Aksel Willgert Avatar asked May 02 '19 09:05

Aksel Willgert


1 Answers

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

like image 109
m4gic Avatar answered Oct 07 '22 23:10

m4gic