Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to add an additional connector in spring boot's application?
import org.apache.catalina.connector.Connector;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class SpringApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(SpringApplication.class).run();
}
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setPort(8081);
tomcat.addAdditionalTomcatConnectors(connector);
return tomcat;
}
}
@lotabout

This comment has been minimized.

Copy link
Owner Author

@lotabout lotabout commented Aug 26, 2019

Untitled Diagram

Say your main thread is blocking waiting for another service's callback. And the max worker thread number is 200. Then say

  • You received 200 requests, they are all blocking waiting for callback.
  • Now the callback request come but you have no more threads for processing it.
    So that your whole system is dead lock.

Thus we need to preserve some threads for our callback endpoint/controller.

The only way that I found is to create another connector(with another port) for the callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment