J'utilise Formscanner et son traitement après quelques images de son donnant l'erreur:Exception dans le thread « principal » java.lang.OutOfMemoryError: impossible de créer un nouveau fil natif
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:717)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:950)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at com.albertoborsetta.formscanner.api.FormTemplate.findPoints(FormTemplate.java:852)
at com.albertoborsetta.formscanner.model.FormScannerModel.analyzeFiles(FormScannerModel.java:562)
at com.albertoborsetta.formscanner.main.FormScanner.main(FormScanner.java:145)
la méthode des points FIND est aussi dans:
public void findPoints(BufferedImage image, int threshold, int density,
int size) throws FormScannerException {
height = image.getHeight();
width = image.getWidth();
int cores = Runtime.getRuntime().availableProcessors();
ExecutorService threadPool = Executors.newFixedThreadPool(cores - 1);
HashSet<Future<HashMap<String, FormQuestion>>> fieldDetectorThreads = new HashSet<>();
HashMap<String, FormQuestion> templateFields = template.getFields();
ArrayList<String> fieldNames = new ArrayList<>(templateFields.keySet());
Collections.sort(fieldNames);
for (String fieldName : fieldNames) {
Future<HashMap<String, FormQuestion>> future = threadPool.submit(new FieldDetector(threshold, density, size, this, templateFields.get(fieldName), image));
fieldDetectorThreads.add(future);
}
for (Future<HashMap<String, FormQuestion>> thread : fieldDetectorThreads) {
try {
HashMap<String, FormQuestion> threadFields = thread.get();
for (String fieldName : threadFields.keySet()) {
FormQuestion field = threadFields.get(fieldName);
fields.put(fieldName, field);
for (Entry<String, FormPoint> point : field.getPoints().entrySet()) {
if (point.getValue() != null) {
pointList.add(point.getValue());
}
}
}
} catch (InterruptedException | ExecutionException e) {
throw new FormScannerException(e.getCause());
}
}
threadPool.shutdown();
}
la fonction ci-dessus est appelée dans la boucle et le nombre de processus Java se développe et en un point soulève l'exception ci-dessus.
Est-il possible que ces threads soient arrêtés après l'appel de la méthode shutdown? Je ne suis pas un développeur Java. J'ai fait quelques R & D. Mais je ne réussis pas.
Courez-vous une JVM de 32 ou 64 bits? Quel est le système d'exploitation utilisé? Quels sont les paramètres de la mémoire (Xmx, Xms, Xss ...)? –
Le pool est supposé limiter le nombre de threads en cours d'exécution et vous avez un 'thread.get' qui attend que chaque thread se termine. Donc, à moins que vous n'appeliez cette méthode dans de nouveaux threads (qui seraient visibles dans la stacktrace), je ne vois pas comment cela pourrait être surchargé. ** Mais bien sûr, il pourrait s'agir de la première instance de FieldDetectors qui prend toute la mémoire disponible **. Que va faire l'instance de FieldDetector? – AxelH
Im utilisant Ubuntu 64bit avec openjdk – Baran