The problem of multithread traversing list under multiple concurrency

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?

Is

all right?


now that the thread pool has been used, there is no problem that threads are created in large numbers. Java7 has come up with a Fork/Join framework, which uses multithreaded parallel computing, which is somewhat similar to this business. The landlord can learn about


without looking at the code. This is obviously a serial task and local parallel processing. To simplify it, you can use thread pool and countdownlatch to do
. Upstairs, you can use the Fork/Join framework to divide and conquer. In fact, if you support jdk8 , You can also use parallel flow parallelstream . The bottom layer is Fork/Join . If you want to code, I'll write

for you later.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3349e-2be7c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3349e-2be7c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?