Author: chatellier Date: 2009-06-30 08:29:44 +0000 (Tue, 30 Jun 2009) New Revision: 2445 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java Log: Ajout d'un synchronized sur this (pour pas que le hasNext() soit fait par 2 jobs ?\195?\160 la fois) Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2009-06-30 08:22:36 UTC (rev 2444) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SimulationService.java 2009-06-30 08:29:44 UTC (rev 2445) @@ -733,64 +733,70 @@ // and if last doNext is false not do next simulation boolean result = !control.isStopSimulationRequest() && doNext; if (result) { - // si deja creer on ne le refet pas - if (nextJob == null) { - // Prepration de la simulation a faire - // create next id simulation - - // this start a 0 - int planNumber = planContext.getNumber(); - - if (planNumber > MAX_PLAN_SIMULATION) { - log.error(_("Analyse plan error, too many simulation for %s : %s", - id, planNumber)); - doNext = false; - result = false; - } else { - String simId = id + "_" + planNumber; - param.setAnalysePlanNumber(planNumber); - - File tmpDirectory = FileUtil.createTempDirectory( - "isisfish-simulation-", "-preparation"); - SimulationStorage sim = SimulationStorage - .importAndRenameZip(tmpDirectory, job - .getItem().getSimulationZip(), + + // hasNext() est appelee par un autre thread concurrent + // via la methode finished(SimulationJob, SimulationStorage) + synchronized (this) { + + // si deja creer on ne le refet pas + if (nextJob == null) { + // Prepration de la simulation a faire + // create next id simulation + + // this start a 0 + int planNumber = planContext.getNumber(); + + if (planNumber > MAX_PLAN_SIMULATION) { + log.error(_("Analyse plan error, too many simulation for %s : %s", + id, planNumber)); + doNext = false; + result = false; + } else { + String simId = id + "_" + planNumber; + param.setAnalysePlanNumber(planNumber); + + File tmpDirectory = FileUtil.createTempDirectory( + "isisfish-simulation-", "-preparation"); + SimulationStorage sim = SimulationStorage + .importAndRenameZip(tmpDirectory, job + .getItem().getSimulationZip(), + simId); + sim.getParameter().setAnalysePlanNumber(planNumber); + + // appel de tous les plans pour modifier la simulation + for (AnalysePlan plan : param.getAnalysePlans()) { + result = result + && plan.beforeSimulation(planContext, + sim); + if (!result) { + nextJob = null; + break; + } + } + doNext = result; + if (result) { + File zip = sim.createZip(); + SimulationControl childControl = new SimulationControl( simId); - sim.getParameter().setAnalysePlanNumber(planNumber); - - // appel de tous les plans pour modifier la simulation - for (AnalysePlan plan : param.getAnalysePlans()) { - result = result - && plan.beforeSimulation(planContext, - sim); - if (!result) { - nextJob = null; - break; + SimulationParameter childParam = param.copy(); + SimulationItem item = new SimulationItem( + childControl, childParam); + item.setSimulationZip(zip); + nextJob = new SimulationJob(simulationService, + job, item, job.getPriority()); + nextJob.setLauncher(job.getLauncher()); + nextJob.addPostAction(this); // pour l'appel des after des plans } + // quoi qu'il arrive on supprime le repertoire temporaire + if (!FileUtil.deleteRecursively(tmpDirectory)) { + log.warn(_("isisfish.error.remove.directory", + tmpDirectory)); + } } - doNext = result; - if (result) { - File zip = sim.createZip(); - SimulationControl childControl = new SimulationControl( - simId); - SimulationParameter childParam = param.copy(); - SimulationItem item = new SimulationItem( - childControl, childParam); - item.setSimulationZip(zip); - nextJob = new SimulationJob(simulationService, - job, item, job.getPriority()); - nextJob.setLauncher(job.getLauncher()); - nextJob.addPostAction(this); // pour l'appel des after des plans - } - // quoi qu'il arrive on supprime le repertoire temporaire - if (!FileUtil.deleteRecursively(tmpDirectory)) { - log.warn(_("isisfish.error.remove.directory", - tmpDirectory)); - } + + // increment number for next simulation job + planContext.incNumber(); } - - // increment number for next simulation job - planContext.incNumber(); } } return result;