Impossible de créer de nouveaux threads
Bonjour,
j'ai une classe dans laquelle je créé des threads que je stocke dans un tableau :
Code:
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
|
if ( threads == null || threads.length != nbCPU )
{
nbFreeThreads = 0 ; // Aucun thread n'est pour l'instant utilisable.
StopThreads() ; // On tue éventuellement ce qu'il doit l'être.
threads = new FuzzyGLRthread[nbCPU] ; // Création du nouveau tableau
for (i=0 ; i < nbCPU ; i++)
{
threads[i] = new FuzzyGLRthread() ;
threads[i].start() ;
}
synchronized (this) // Je vérifie / attends que les threads démarrent.
{
while ( nbFreeThreads != nbCPU ) // On attends la fin de la creation de chaque thread.
try {
wait() ;
}
catch ( InterruptedException e )
{
e.printStackTrace() ;
}
}
} |
Afin de m'assurer que mes threads soient correctement tués, j'utilise cette méthode :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
private void StopThreads()
{
if ( threads == null ) return ;
for (int i=0 ; i < threads.length ; i++)
try {
threads[i].interrupt() ; // Wait its death.
threads[i].join() ; // Wait its death.
threads[i] = null ;
}
catch ( InterruptedException ex )
{
System.err.println("Souci") ;
}
threads = null ;
System.gc() ;
} |
Je fais cela, parce que la classe utilisant cette méthode est appelée un TRES grands nombre de fois, donc je souhaite être certains que je n'ai pas de threads encore actifs.
Mais voilà, durant l'exécution, j'ai cette exception :
Citation:
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:658)
at imageTiTi.reducer.FuzzyGLR.Reduce(FuzzyGLR.java:147)
at characterization.textures.thibaultmatrices.fuzzy.szm.MultiFuzzySZM.Compute(MultiFuzzySZM.java:173)
at softwares.challenges.icip2013.CharacterizeCells.Process(CharacterizeCells.java:120)
at prototyper.Prototyper.main(Prototyper.java:295)
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:658)
at imageTiTi.reducer.FuzzyGLR.Reduce(FuzzyGLR.java:147)
at characterization.textures.thibaultmatrices.fuzzy.szm.MultiFuzzySZM.Compute(MultiFuzzySZM.java:173)
at softwares.challenges.icip2013.CharacterizeCells.Process(CharacterizeCells.java:120)
at prototyper.Prototyper.main(Prototyper.java:295)
Exception in thread "main" java.lang.NullPointerException
at utils.LogFile.addNewError(LogFile.java:80)
at softwares.challenges.icip2013.CharacterizeCells.Process(CharacterizeCells.java:140)
at prototyper.Prototyper.main(Prototyper.java:295)
Et là attention, je dois tuer le processus via mon système car NetBeans n'arrive même pas à le faire.
Est ce que quelqu'un saurait d'où vient le problème ?
Je comprends encore moins
J'ai modifié ma méthode StopThreads afin qu'elle dise au thread de se suicider : il appelle lui même la méthode "interrupt", puis un break pour sortir de la méthode run().
Cela me permet d'aller quatre fois plus loin dans le traitement de mes données, mais la même erreur survient :
Citation:
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:658)
at imageTiTi.reducer.FuzzyGLR.Reduce(FuzzyGLR.java:149)
at characterization.textures.thibaultmatrices.fuzzy.szm.MultiFuzzySZM.Compute(MultiFuzzySZM.java:173)
at softwares.challenges.icip2013.CharacterizeCells.Process(CharacterizeCells.java:120)
at prototyper.Prototyper.main(Prototyper.java:295)
Qu'est ce que je ne comprends pas ?