Bonjour
Voici mon problème. Ma première version d'un logiciel utilisait des threads exécutés de la manière la plus classique:
Notez d'ailleurs la variable "projet" qui est un objet contenant une List.
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 @Override protected void getProjectCompoundsAndResults(Project project) throws IOException, SQLException { CompoundsGetter cg = new CompoundsGetter(project, this.forCompoundLot); Thread thread = new Thread(cg); thread.start(); while (thread.isAlive()) { try { Thread.sleep(500); } catch (InterruptedException ex) {} } }
Puis, dans un souci d'être à la pointe, je me suis dis que c'était pas mal d'utiliser les Excecutor:
Ca compile et ça s'exécute bien sauf qu'au debbugage, je peux voir qu'à l'initialisation, ma variable projet a bien sa List remplie mais dès que je suis en exécution (pool.submit(cg)
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 @Override protected void getProjectCompoundsAndResults(Project project) throws IOException, SQLException { CompoundsGetter cg = new CompoundsGetter(project, this.forCompoundLot); //Thread thread = new Thread(cg); ExecutorService pool = Executors.newSingleThreadExecutor(); pool.submit(cg); pool.shutdown(); /*thread.start(); while (thread.isAlive()) { try { Thread.sleep(500); } catch (InterruptedException ex) {} }*/ }, la liste apparaît vide !
Une précision, voici comment la méthode getProjectCompoundsAndResults est invoquée:
Merci d'avance de votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 protected void writeProject(ResultSet rs) throws SQLException, IOException { Logger.getLogger(ProjectsGetter.class.getName()).log(Level.INFO, "Creating project {0}", rs.getString(2)); Project project = new Project(rs.getInt(1), rs.getString(2), rs.getString(3)); setProjectExperiments(project); getProjectCompoundsAndResults(project); project.getExperiments().clear(); }
@++
Partager