Java:
public void createForXMLFile(File[] files) throws Exception {
Thread thread = new Thread(() -> {
File[] files1 = new File[files.length / 4];
int count = 0;
for (int j = 0; j < files.length / 4; j++) {
files1[count++] = files[j];
if (count == files1.length) {
break;
}
}
try {
Document doc = merge("/Bestellung/", files1);
write(doc);
} catch (Exception e) {
}
});
Thread thread1 = new Thread(() -> {
File[] files2 = new File[files.length / 4];
int count = 0;
for (int j = files.length / 4; j < files.length / 2; j++) {
files2[count++] = files[j];
if (count == files2.length) {
break;
}
}
try {
Document doc = merge("/Bestellung/", files2);
write(doc);
} catch (Exception e) {
}
});
Thread thread2 = new Thread(() -> {
File[] files3 = new File[files.length / 4];
int count = 0;
for (int j = files.length / 2; j < files.length; j++) {
files3[count++] = files[j];
if (count == files3.length) {
break;
}
}
try {
Document doc = merge("/Bestellung/", files3);
write(doc);
} catch (Exception e) {
}
});
Thread thread3 = new Thread(() -> {
int help = 0;
final int i = files.length - (files.length / 4) * 3;
File[] files4 = new File[i];
help = files.length - i;
int count = 0;
for (int j = help; j < files.length; j++) {
files4[count++] = files[j];
if (count == files4.length) {
break;
}
}
try {
Document doc = merge("/Bestellung/", files4);
write(doc);
} catch (Exception e) {
}
});
thread.start();
thread1.start();
thread2.start();
thread3.start();
thread.join();
thread1.join();
thread2.join();
thread3.join();
}
Guten Tag liebe Leute,
Ich mach Einstieg in Thread, daher wollte gern fragen, ob ich hier alles richtig gemacht habe.
Also wenn ich diese Method aufrufe, macht alles was gewünscht ist, aber mit Thread hatte ich vorher nicht viele Erfahrung. Daher wenn euch irgendwas auffällt, was ich nicht sehen kann, und mir Anmerkungen geben, würde ich so verbessern...
Vielen Dank im Voraus