私はRESTアプリケーション(スタック:Java8/Tomcat7/Spring4.2/Jersey2.15)を使用し、RESTエンドポイントでスレッドプール(ThreadPoolExecutor)を使用します。ThreadPoolExecutorのシャットダウンについて気にする必要はありますか?
private ThreadPoolExecutor threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
エンドポイントクラスは、スプリング注釈@Component(それはデフォルトでシングルトンである)で構成されています。 ThreadPoolExecutorのjavadocの
は、私は、この読み取り:私はシャットダウンになりますthreadPool.shutdown()プールを呼び出さないようにするとき
Finalization A pool that is no longer referenced in a program AND has no remaining threads will be shutdown automatically. If you would like to ensure that unreferenced pools are reclaimed even if users forget to call shutdown(), then you must arrange that unused threads eventually die, by setting appropriate keep-alive times, using a lower bound of zero core threads and/or setting allowCoreThreadTimeOut(boolean).
をする場合、通常この場合ときでアプリケーションが終了します( tomcatがシャットダウンするか、アプリケーションが停止します)。
私の質問は次のとおりです。プールのシャットダウンに注意する必要がありますか?副作用が起きる可能性はありますか? (例えば、memのリーク、長いTomcatのシャットダウン時間、...)それは堅実ですか?
私はthreadPoolのシャットダウンを追加するべきだと思っていたでしょう。 Spring ThreadPoolTaskExecutorは、このレガシーアプリケーションの将来のリファクタリングのための考慮事項です。 ATMにはthreadPoolsの場所が多すぎるので、小さなステップで変更を行いたい。 – Erik
それは本当の挑戦です!私は最高をお祈りします! – gkatzioura