Skip to content

Instantly share code, notes, and snippets.

@lotabout
Created August 26, 2019 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotabout/fb02706c9cb210426c259d2475fb5a70 to your computer and use it in GitHub Desktop.
Save lotabout/fb02706c9cb210426c259d2475fb5a70 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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