スプリング ブート フレームワークと桟橋をコンテナーとして使用してスプリング レスト サービスを作成しています。コントローラーでは、このように callable を使用しました。
@RequestMapping(value = "/{key}/events", method = RequestMethod.GET)
public Callable<String> getEvents(@PathVariable("key") final String key,
@RequestParam(required = false) final String startAt,
@RequestParam(required = false) final String maxResults) {
return new Callable<String>() {
@Override
public String call() throws Exception {
// here logic that return json string
}
}
}
そして、私がこのように書いたサーブレットコンテナファクトリー
@Bean
public EmbeddedServletContainerFactory servletContainer(){
JettyEmbeddedServletContainerFactory jetty=new JettyEmbeddedServletContainerFactory();
jetty.addServerCustomizers(new JettyServerCustomizer() {
@Override
public void customize(final Server server) {
// Tweak the connection pool used by Jetty to handle incoming HTTP connections
final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
threadPool.setMaxThreads(Integer.valueOf(200));
threadPool.setMinThreads(Integer.valueOf(100));
threadPool.setIdleTimeout(Integer.valueOf(100000));
threadPool.setStopTimeout(10000);
}
});
jetty.setPort(4040);
jetty.setContextPath("/mycontextpath");
return jetty;
}
今私の問題は、アプリケーションを実行するときです。
初めてブラウザーから URL にアクセスすると、出力が得られません (jetty サーバーからのサービスが利用できないというメッセージが表示されます)。
しかし、再び URL を 2 回目、3 回目、4 回目にヒットすると、出力が得られます。
Callable を Controller として実装するには、何か不足していますか?
コードをデバッグしたところ、初回の内部処理がまだ進行中であり、ブラウザーが完全な応答を返していることがわかりました...
では私は何をすべきか?提案してください、
私の主な目的は、コントローラーが特定の時間により多くのクライアント要求を受け入れて応答することです。