Today, there are 30,000 pieces of data found by export. The result of processing will be timed out.
think of multithread traversing list to find this code on the Internet:
public String list2Str(List<String> list, final int nThreads) throws Exception {
if (list == null || list.isEmpty()) {
return null;
}
StringBuffer ret = new StringBuffer();
int size = list.size();
ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
List<Future<String>> futures = new ArrayList<Future<String>>(nThreads);
for (int i = 0; i < nThreads; iPP) {
final List<String> subList = list.subList(size / nThreads * i, size / nThreads * (i + 1));
Callable<String> task = new Callable<String>() {
@Override
public String call() throws Exception {
StringBuffer sb = new StringBuffer();
for (String str : subList) {
sb.append(str);
}
return sb.toString();
}
};
futures.add(executorService.submit(task));
}
for (Future<String> future : futures) {
ret.append(future.get());
}
executorService.shutdown();
return ret.toString();
}
}
when I called, I opened 5 threads. I want to ask you to open 5 threads for each export. if multiple people export at the same time, say 10000 people at the same time, wouldn"t it be 50000 threads?
Isall right?