私のコード:
String[] torrentFiles = new File("/root/torrents/").list();
if(torrentFiles.length == 0 || torrentFiles == null)
{
System.exit(0);
}
ex = Executors.newFixedThreadPool(3);
for(String torrentFile : torrentFiles)
{
ex.submit(new DownloadTorrent("/root/torrents/" + torrentFile));
}
ex.shutdown();
try
{
ex.awaitTermination(30, TimeUnit.MINUTES);
}
catch(InterruptedException ex1)
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex1);
}
しかし、トレントのダウンロードには不明な時間値がかかり、« awaitTermination
» が思い通りに動作しないことがあります。実行されたすべてのスレッドを30分後に即座に停止する必要がありますが、私が知っているように、« awaitTermination
»interrupt()
はループまたは待機でのみ機能するメソッドのみを使用します. したがって、この瞬間が発生した場合、タイムアウトは機能しません。それで、どうやって?