Bonjour,
J'ai créé mon propre shell sur un serveur linux que je dois appeler depuis une application web sous tomcat.
J'utilise l'API d'adiguba concernant les shell qui, en principe, règle les pbs d'entrée-sortie des flux.
J'ai encapsulé l'appele de ce shell danjs un thread, comme suit :
Puis dans mon appli web, j'appelle ce thread tout simplement avec la méthode
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 package fr.britair.analyzerPVE.thread; import java.io.IOException; import org.apache.log4j.Logger; import com.developpez.adiguba.shell.ProcessConsumer; import com.developpez.adiguba.shell.Shell; import fr.britair.analyzerPVE.constants.Constants; public class ThreadGenerationPVE implements Runnable{ /** Logger. */ private static Logger log = Logger.getLogger(ThreadGenerationPVE.class); private long tempsAttenteAvantVerificationPVEGenere; String[] parametresFormatagePVE = new String[9]; public String[] getParametresFormatagePVE() { return parametresFormatagePVE; } public void setParametresFormatagePVE(String[] parametresFormatagePVE) { this.parametresFormatagePVE = parametresFormatagePVE; } public void run() { // MainClientSafetyPveGenerator.main(getParametresFormatagePVE()); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(Constants.RUN_SHELL_PVE); stringBuilder.append(" "); for (int i = 0; i < getParametresFormatagePVE().length; i++) { if (i!=5) stringBuilder.append(getParametresFormatagePVE()[i]); else stringBuilder.append("\""+getParametresFormatagePVE()[i]+"\""); if (i != getParametresFormatagePVE().length-1) stringBuilder.append(" "); } log.error("COMMANDE SHELL = " +stringBuilder.toString()); Shell shell = new Shell(); ProcessConsumer process = shell.command(stringBuilder.toString()); try { int result = process.consume(); } catch (Exception e) { log.error("IOException dans l'execution du Shell " + Constants.RUN_SHELL_PVE); e.printStackTrace(); } } public long getTempsAttenteAvantVerificationPVEGenere() { return tempsAttenteAvantVerificationPVEGenere; } public void setTempsAttenteAvantVerificationPVEGenere( long tempsAttenteAvantVerificationPVEGenere) { this.tempsAttenteAvantVerificationPVEGenere = tempsAttenteAvantVerificationPVEGenere; } }
'start' du thread.
Le shell est censé me générer ou pas des fichiers XML.
Il m'arrive parfois dans mon code d'iterer plusieurs fois l'appel à ce thread qui m'execute mon Shell linux, de la façon suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 for(Object[] objects : listeRoutes) { ThreadGenerationRoute threadGenerationRoute = new ThreadGenerationRoute(); threadGenerationRoute.setParametresGenerationRoute(parametresGenerationRoute); Thread t = new Thread(threadGenerationRoute); /** Appel du gestionnaire PVE **/ log.error("##### APPEL DU GESTIONNAIRE DE GENERATION D'UNE ROUTE SECOURS pour la Route " + aeroportDepart+"/"+aeroportArrivee+"/"+groupeAvion+"/"+route); t.start(); try { int nb=0; //On vérifie si le fichier est arrivé toutes les 50 sec. while(!verifiePresenceFichierLogSecoursGenere(fichierGenere) && nb<12) { log.error("##### On attend "+(50000)/1000+" sec. de plus avant de verifier si le fichier XML de la route est là"); Thread.sleep(50000); nb++; } } catch (InterruptedException e1) { throw new CommonsRuntimeException("InterruptedException dans la méthode sleep du Thread courant d'appel à la génération de route "); } // log.error("## INTERRUPTION DE L'APPEL A LA GENERATION DE LA ROUTE ##"); t.interrupt(); } //fin for }
Or il se trouve que j'ai toujours des IOException lorsque j'appelle ce thread plusieurs fois avec mon itération de la boucke for.
Je pensais que l'API d'adiguba réglait les pbs d'I/O mais apparemment j'ai tjs des pbs d'I/O, ce qui a pour effet d'arreter le serveur TOMCAT lorsque cette Exception est rencontrée.
Quelq'un aurait il une idée ?
Merci.
Partager