美文网首页
在springboot中扩展tomcat的executor

在springboot中扩展tomcat的executor

作者: tommyhxh | 来源:发表于2017-04-19 13:34 被阅读0次

springboot 中对tomcat容器做优化,

注意是否只启动了一个tomcat和一个connector

public class AdvancedThreadExecutor extends StandardThreadExecutor {
    @Override
    protected void startInternal() throws LifecycleException {
        super.namePrefix = "custom-tomcat-";
        super.maxThreads =?minSpareThreads ,maxIdleTime 
        
        super.startInternal();
        executor.setRejectedExecutionHandler(new RejectedExecutionHandler() {
            @Override
            public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                //add stat
                throw new RejectedExecutionException("Task " + r.toString() +
                        " rejected from " +
                        executor.toString());
            }
        });
    }
}
@Component
public class EmbeddedTomcatConfig implements 
EmbeddedServletContainerCustomizer {

    private static final Logger logger = LoggerFactory.getLogger(EmbeddedTomcatConfig.class);

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        if(container instanceof TomcatEmbeddedServletContainerFactory){
            TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory)container;
            factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
                @Override
                public void customize(Connector connector) {
                    AdvancedThreadExecutor myExecutor = 
new AdvancedThreadExecutor();
                    connector.getService().addExecutor(myExecutor);
                    ProtocolHandler handler = connector.getProtocolHandler();
                    Http11NioProtocol http11NioProtocol = (Http11NioProtocol)handler;
                    http11NioProtocol.setExecutor(myExecutor);
                }
            });
        }
    }
}

相关文章

网友评论

      本文标题:在springboot中扩展tomcat的executor

      本文链接:https://www.haomeiwen.com/subject/ppoczttx.html