JMSから受信したExchangeの処理中に、FTPからファイルシステムにファイルをフェッチするルートを動的に作成しています。その同じルートを削除する必要があります。次のコードは、私がこれを行う方法を示しています。経路を停止/削除すると、動的に/プログラム的に対応するスレッドが削除されない
public void execute() {
try {
context.addRoutes(createFetchIndexRoute(routeId()));
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
private RouteBuilder createFetchIndexRoute(final String routeId) {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("ftp://" + getRemoteQuarterDirectory() +
"?fileName=" + location.getFileName() +
"&binary=true" +
"&localWorkDirectory=" + localWorkDirectory)
.to("file://" + getLocalQuarterDirectory())
.process(new Processor() {
RouteTerminator terminator;
@Override
public void process(Exchange exchange) throws Exception {
if (camelBatchComplete(exchange)) {
terminator = new RouteTerminator(routeId,
exchange.getContext());
terminator.start();
}
}
})
.routeId(routeId);
}
};
}
私はキャメルドキュメントで推奨されるアプローチであるルート、からのルートを停止するには、スレッドを使用しています - How can I stop a route from a route
public class RouteTerminator extends Thread {
private String routeId;
private CamelContext camelContext;
public RouteTerminator(String routeId, CamelContext camelContext) {
this.routeId = routeId;
this.camelContext = camelContext;
}
@Override
public void run() {
try {
camelContext.stopRoute(routeId);
camelContext.removeRoute(routeId);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
}
結果として、ルートは停止します。しかし、私がのjconsoleに表示されているのは、ルートに対応するスレッドが削除されないということです。このように時間のこれらの放棄スレッドはちょうど蓄積し続ける。
経路を動的に/プログラム的に適切に停止/削除する方法と、経路のスレッドを解放する方法があるため、時間がたつと蓄積されませんか?
2.9.2-SNAPSHOTに切り替えました。現在、生きているスレッドの数は安定しており、前と同じように蓄積されません。 –