J'ai un programme dans lequel je télécharge des fichiers de S3 en utilisant un objet Callable soumis à un ExecutorService. Les fichiers sont volumineux et prennent plusieurs minutes pour être entièrement téléchargés. Est-il logique de créer une autre classe Callable qui prend l'avenir du téléchargeur et le regarde pour l'achèvement? Mon objectif final est d'ajouter tous les téléchargements complets à une liste centralisée dans un cache.Regarder à l'avenir <T> Objets à compléter avec ExecutorService
Par exemple:
public void add(final String s3urlToDownload){
Future<S3Object> futureS3obj = cachedPoolExecutor.submit(new S3Downloader(s3urlToDownload));
// Instead of calling futureS3obj.get() and waiting, submit the Future to the "Watcher" service.
// Within FutureWatcher, the S3Object will be added to the List once the download is complete.
cachedPoolExecutor.submit(new FutureWatcher(downloadedList, futureS3obj))
}
Quel est l'avantage d'un 'Callable' supplémentaire si vous avez déjà un' Future'? – Kayaman
@Kayaman, À ma connaissance, si j'appelais la méthode 'future'' get() ', la méthode' add' bloquerait. C'est pourquoi je soumets un nouvel appelable 'FutureWatcher' – dmux
Alors, qu'est-ce que' Callable' apporte? Appeler sa méthode 'call()' bloquerait aussi, puisqu'il délègue 'get()'. – Kayaman