package test;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.List;import com.dbn.oatong.sysmodule.utils.DbnBase64;import com.dbn.oatong.sysmodule.utils.QRUtil;/** * 个人二维码 * @author * */public class PersonTwoDimensional { public static void main(String[] args) throws Exception {/*// String base64Str = new String(DbnBase64.encode("999933363184714496", "")); String base64Str = new String(DbnBase64.encode("635825967106673738", ""));// String base64Str = new String(DbnBase64.encode("1", "")); String content = "http://xxx/ocr/person/scanUserInfo.action?p&code=" + base64Str;// String content = "http://xxx/ocr/person/scanUserInfo.action?code=1";// String content = "1"; int width = 472; int height = 472;// int bgFlag = 8;// int degree = 18; String blankPath = "";//白色边框,不需要 String modelPath = "";//头像,不需要 String imagePath = "D:\\testTwoDemison2.png"; String fileServerUrl = "";//上传用的,这里不需要 String uploadSource = "";//上传用的,这里不需要 String uploadKey = "";//上传用的,这里不需要 String qrImgPath = QRUtil.encode(content, width, height, imagePath);*/ final String topFolder = "D:\\EmpQRCode\\"; String dataTxt = "D:\\empData.txt"; BufferedReader br = new BufferedReader(new FileReader(new File(dataTxt))); int lineNum = 34799;//总共34799行 final ListlineArr = new ArrayList (lineNum); String lineStr = null; long startTime = System.currentTimeMillis(); while ((lineStr = br.readLine()) != null) { lineArr.add(lineStr); } br.close(); long endTime = System.currentTimeMillis(); System.out.println("读取文件耗时:" + (endTime - startTime)); int threadNum = 10;//处理的总线程数 int batchItems = lineNum / threadNum;//每个线程处理的行数 for (int i = 0; i < threadNum; i++) { final int beginLineNum = i * batchItems; final int endLineNum; if (i == threadNum - 1) { endLineNum = lineNum - 1; } else { endLineNum = (i + 1) * batchItems - 1; } final int threadId = i; Thread t = new Thread("线程" + i) { public void run() { long begin = System.currentTimeMillis(); //每个线程分别处理相应的任务 for (int j = beginLineNum; j <= endLineNum; j++) { String userData = lineArr.get(j); String[] userDataArr = userData.split("\\|"); //具体的任务处理 String base64Id = new String(DbnBase64.encode(userDataArr[0], "")); String qrCodeContent = "http://xxx/ocr/person/scanUserInfo.action?p&code=" + base64Id; String folderStr = topFolder + userDataArr[3] + threadId; File folder = new File(folderStr); if (!folder.exists()) { folder.mkdir(); } String userName = userDataArr[1].replace("*", ""); String qrImgPath = folderStr + "\\" + userName + "_" + userDataArr[2] + ".png"; QRUtil.encode(qrCodeContent, 472, 472, qrImgPath); } long end = System.currentTimeMillis(); System.out.println(this.getName() + "耗时:" + (end - begin)); } }; t.start(); } }}/** * * * 读取文件耗时:22线程0耗时:203727线程9耗时:203896线程1耗时:203914线程5耗时:204127线程7耗时:204374线程3耗时:204394线程8耗时:204691线程6耗时:204874线程2耗时:205123线程4耗时:205339 * * * * * * * * * * */