J'ai une petite application de traitement d'image qui fait plusieurs choses à la fois en utilisant SwingWorker. Cependant, si je cours le code suivant (extrait simplifié), il se bloque simplement sur JDK 7 b70 (windows) mais fonctionne en 6u16. Il démarre un nouveau worker dans un autre worker et attend son résultat (l'application réelle exécute plusieurs sous-workers et attend tout cela). Ai-je utilisé de mauvais modèles ici (comme il y a surtout 3-5 travailleurs dans la piscine de swingworker, qui a une limite de 10 je pense)?JDK-7 Deadlocks SwingWorker?
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
public class Swing {
static SwingWorker<String, Void> getWorker2() {
return new SwingWorker<String, Void>() {
@Override
protected String doInBackground() throws Exception {
return "Hello World";
}
};
}
static void runWorker() {
SwingWorker<String, Void> worker
= new SwingWorker<String, Void>() {
@Override
protected String doInBackground() throws Exception {
SwingWorker<String, Void> sw2 = getWorker2();
sw2.execute();
return sw2.get();
}
};
worker.execute();
try {
System.out.println(worker.get());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
runWorker();
}
});
}
}
Avez-vous essayé d'obtenir un vidage de pile? –
Il semble qu'il se bloque sur sw2.get() et il n'y a qu'un seul thread nommé par swingworker dans jdk7. Sur jdk6, je vois 3-5 à la fois. – akarnokd