////////////// Currently, a file processing 50 million rows needs to be segmented by rows .. it takes 50 s to complete .. after debugging, the bottleneck lies in this code... tokenStream ts = Analyzer. tokenStream ("", reader); changed to IKSegmenter ., // IKSegmenter ik = new IKSegmenter (reader, true); machine environment: win7 64bit .. cpu dual-core, 2.7g..8 GB memory view cpu usage, only one cpu is used, and the other is idle... to use it all, the performance should be improved by 2 times .. ////////// use multiple threads to Improve the Performance of multi-core cpu .. with the continuous upgrade of the hardware, the CPU core of the computer has become a versatile guy. The experts who designed it claim that this can maximize program running efficiency. But is that true? As we all know, most of today's programs are designed based on a single thread. However, if this design mode runs on a single-core CPU with a high clock speed, the efficiency is very high. However, it cannot coordinate the multi-core tasks well. Unfortunately, a single-threaded program runs on a multi-core CPU and may not even have a single-core CPU. Of course, for now, the best way to solve this soft performance bottleneck is the multi-threaded programming discussed in this topic. Only by making full use of this technology can we maximize the potential of multiple cores. Well, let's talk about it. Finally, let's use the content in this topic to enjoy the surprises and excitement that multi-core brings to us! 2. The difference between thread decomposition and execution: multithreading is used for single-core CPU and client software. It is mainly used to create multiple threads to execute some computing tasks in the background without affecting user interaction. (User Interface & other computing operations in parallel) to improve user operation performance! In a multi-core architecture, multiple threads are generated, which is no longer limited to separating User Interface operations from other computations. Multiple Threads are decomposed so that computing is allocated to each CPU for execution. The number of execution threads is related to the number of CPU cores! If the number of threads is smaller than the number of cores, some CPUs must be idle. 3. Load Balancing of CPU cores: the single core does not consider load balancing. The computing workload of each thread varies greatly, and the total computing time of the program is not affected. In multiple cores, the computing workload of each thread must be balanced to CPU 7, the differences between serial computing and parallel computing and distributed computing among single-core multi-thread programming are all serial algorithms. Parallel Computing is not used, and distributed computing multi-core programming is not used, parallel Computing and distributed computing are mostly used. Parallel Computing = parallel design mode + parallel algorithm distributed computing complexity> parallel computing complexity> serial computing complexity parallel computing: only parallel computing execution is considered, without considering the competition between threads, CPU hunger Distributed Computing: Compared with parallel computing, it can better solve CPU hunger, make the computing evenly allocate tasks to each kernel ///////////////// the code is as follows: after testing, because there are only two cpu cores, two threads from Kerry .. sure enough, the two CPUs occupy 100% yuan of blue, and the time is half of the original in the city .. 25 s go to OK lan... list <String> lica7 = fc. fileRead2list (sourceTxt, "UTF-8"); int mid = lica7.size ()/2; final List <String> lica7_half1 = lica7.subList (0, mid ); list <String> lica7_half2 = lica7.subList (mid, lica7.size (); new Thread >>>> lica7_half1_result = ftc. fentsiMuilttheard (lica7_half1, wordLibs, "thd1"); half1_isfinesh = true; // main thread // wait 4 half_thread_finish // habin lyag list .. /// // true code. list <String> lica7_half1_result; boolean half1_isfinesh = false; /*** @ author attilax 1466519819@qq.com * @ param sourceTxt * @ param targetTxt * @ param wordLibs * for file line> 5 w bacause 50 w time tooo long, gujyi * 1min... muset rewrite jeig swefa. * @ since cae */public void fentsi4bigfile (String sourceTxt, String targetTxt, final String wordLibs) {// String wordLibs = // "c :\\ wordFromInputmethod.txt, c: \ word.txt, c :\\ ext.txt "; // String sourceTxt =" c: \ sincin.txt "; // String targetTxt =" c: \ fentsiOK.txt "; int n = 0; List <String> li_r = new ArrayList <String> (); fileC0 fc = new fileC0 (); // String text = fc. fileRead (sourceTxt); // if (true) return; List <String> lica7 = fc. fileRead2list (sourceTxt, "UTF-8"); int mid = lica7.size ()/2; final List <String> lica7_half1 = lica7.subList (0, mid ); list <String> lica7_half2 = lica7.subList (mid, lica7.size (); List <String> lica7_half2_result; // n = fentsiMuilttheard (wordLibs, n, lica7 ); new Thread (new Runnable () {public void run () {try {fentsiOr ftc = new fentsiOr (); lica7_half1_result = ftc. fentsiMuilttheard (lica7_half1, wordLibs, "thd1"); half1_isfinesh = true;} catch (Exception e) {e. printStackTrace ();} System. out. println (Thread. currentThread (). getName ());}}). start (); // main threadfentsiOr ftc = new fentsiOr (); lica7_half2_result = ftc. fentsiMuilttheard (lica7_half2, wordLibs, "thd_main"); // stop whiel half is not okint nn = 0; while (true) {if (half1_isfinesh) {break;} nn ++; try {Thread. sleep (50); System. out. println ("-- sleep 500, num:" + nn);} catch (InterruptedException e) {e. printStackTrace (); throw new RuntimeException (e) ;}list <String> li_all = new ArrayList <String> (); li_all.addAll (lica7_half1_result); li_all.addAll (lica7_half2_result. saveList2file (li_all, targetTxt, "UTF-8 ");}