Bonjour,
je fais des requetes sur différentes machines en parrallèle via un pool de thread. Il peut arriver qu'une machine ne me réponde pas, ou soit trop lente, dans ce cas j'aimerai pouvoir libérer le thread. au bout d'un certain temps.
voici ce que j'ai fait :
le problème est que le awaitTermination me donne un timeout sur le pool et non pas pour chaque thread.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 ExecutorService threadExecutor = Executors.newFixedThreadPool( numberOfThreadMax ); for(MonThread thread : threadList) threadExecutor.execute( thread ); //no more thread to add to the pool so we close the pool threadExecutor.shutdown(); //and we wait the end of each thread in the pool try { threadExecutor.awaitTermination(threadTimeOut, TimeUnit.SECONDS) } catch (InterruptedException e) { logger.error(e); throw new ServerErrorException(); }
Merci de votre aide
Partager