调用方法:
/** * 点击量/月(年)Thread */ public void yearlyClickThread() { // 获取参数 String year = getPara("year"); // 统计数据集X ListxList = new ArrayList (); xList.add("January"); xList.add("February"); xList.add("March"); xList.add("April"); xList.add("May"); xList.add("June"); xList.add("July"); xList.add("August"); xList.add("September"); xList.add("October"); xList.add("November"); xList.add("December"); // 统计数据集Y List yList = new ArrayList (); // 统计线程状态 List threadList = new ArrayList (); // 线程状态码 int threadStatusCode = 0; // 计数器 int count = 0; // 每月的日志分析 for (int m = 1; m <= 12; m++) { // 收集日期参数 List dateList = new ArrayList (); // String date = ""; // 判断有多少天 int days = CalendarUtil.weekForMonth(Integer.valueOf(year), m); // 组合日期 for (int i = 1; i <= days; i++) { if (i <= 9) { if (m <= 9) { date = year + "-0" + m + "-0" + i; } else { date = year + "-" + m + "-0" + i; } } else { if (m <= 9) { date = year + "-0" + m + "-" + i; } else { date = year + "-" + m + "-" + i; } } dateList.add(date); } // 启动线程 Thread thread = new ReadLogFileThreadByYear(dateList); thread.start(); try { // 休眠 Thread.sleep(1000L); } catch (InterruptedException e) { e.printStackTrace(); } threadList.add(thread); } // 获取线程状态 for (Thread t : threadList) { if (t.getState().toString().equals("TERMINATED")) { threadStatusCode += 1; } } // 判断线程是否都执行完毕 if (threadStatusCode == 12) { // 接收参数 // List
线程方法:
package com.ninemax.util.loganalysis; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.ninemax.util.loganalysis.tool.ConstantUtil; /** * 多线程无返回值 * * @author Darker * */ public class ReadLogFileThreadByYear extends Thread { // 日期数组 private ListclickDate; // 共享数据 public static List > list = new ArrayList >(); public ReadLogFileThreadByYear(List clickDate) { this.clickDate = clickDate; } /** * 读取点击日志文件 * * 例子:article.click.2016-05-20.txt * * @return */ public void run() { // 接收参数 Map map = new HashMap (); // 利用FileInputStream读取文件信息 FileInputStream fis = null; // 利用InputStreamReader进行转码 InputStreamReader reader = null; // 利用BufferedReader进行缓冲 BufferedReader bufReader = null; // 利用StringBuffer接收文件内容容器 StringBuffer buf = new StringBuffer(); // 点击量/月 int mOnthClick= 0; for (int i = 0; i