Java 反射 函数,多线程调用一个类中不同的方法



public void run()
{
try
{
Class reflectClass = Class.forName("com.zte.ums.zxnm01.common.alarmReport.AlarmDataExport");
Method m = reflectClass.getMethod(methodName, new Class[]{WritableSheet.class, WritableWorkbook.class, GenerationService.class});
m.invoke(reflectClass.newInstance(), new Object[]{ws, wwb, service});
// alarmDataExport.createHistoryReportByOlt(ws, wwb, service);
isOk = true;
}
catch(Exception e)
{
e.printStackTrace();
}

}


public class AlarmThreadHis9 extends Thread
{
private AlarmDataExport alarmDataExport;
private WritableSheet ws;
private WritableWorkbook wwb;
private GenerationService service;
public boolean isOk = false;
private String methodName;

public AlarmThreadHis9(AlarmDataExport alarmDataExport, WritableSheet ws, WritableWorkbook wwb, GenerationService service, String methodName)
{
this.alarmDataExport = alarmDataExport;
this.ws = ws;
this.wwb = wwb;
this.service = service;
this.methodName = methodName;
}

public void run()
{
try
{
Method m = AlarmDataExport.class.getMethod(methodName, new Class[]{WritableSheet.class, WritableWorkbook.class, GenerationService.class});
m.invoke(alarmDataExport, new Object[]{ws, wwb, service});
// alarmDataExport.createHistoryReportByOlt(ws, wwb, service);
isOk = true;
}
catch(Exception e)
{
e.printStackTrace();
}

}

}


public class AlarmThreadHis extends Thread
{
private AlarmDataExport alarmDataExport;

public AlarmThreadHis(AlarmDataExport alarmDataExport)
{
this.alarmDataExport = alarmDataExport;
}

DBOperation[] dbOperations = new DBOperation[8];
GenerationService[] services = new GenerationService[8];
String[] methods = new String[]{"createNeAlarmTotalReport","createHistoryReport",
"createHistoryReportByTime","createInformReport",
"createHistoryReportByOlt","createHistoryReportByOnu",
"createHistoryReportByOnuDownLine","createHistoryReportByNeLinked"};
AlarmThreadHis9[] his9s = new AlarmThreadHis9[8];

public void run()
{
alarmDataExport.printInfoBeforeGenHisAlarmReport();
try
{
String templatePath = Utilities.getTemplateHisAlarmReportPath();
String destFile = alarmDataExport.getUtil().createHisAlarmReportPath();
WritableSheet ws = null;
Workbook hisin = Workbook.getWorkbook(new File(templatePath));
WritableWorkbook wwb = Workbook.createWorkbook(new File(destFile), hisin);
CellDataFormaterManager formaterManager = new CellDataFormaterManager(wwb);


for(int i = 0; i < 8; i++)
{
dbOperations[i] = new DBOperation();
services[i] = new GenerationService(formaterManager, dbOperations[i]);
his9s[i] = new AlarmThreadHis9(alarmDataExport, ws, wwb, services[i],methods[i]);
his9s[i].start();
}
// // alarmDataExport.createNeAlarmTotalReport(ws, wwb, service);
// AlarmThreadHis1 his1 = new AlarmThreadHis1(alarmDataExport, ws, wwb, services[0]);
// // alarmDataExport.createHistoryReport(ws, wwb, service);
// AlarmThreadHis2 his2 = new AlarmThreadHis2(alarmDataExport, ws, wwb, services[1]);
alarmDataExport.createHistoryReportByTime(ws, wwb, service);
// AlarmThreadHis3 his3 = new AlarmThreadHis3(alarmDataExport, ws, wwb, services[2]);
alarmDataExport.createInformReport(ws, wwb, service);
// AlarmThreadHis4 his4 = new AlarmThreadHis4(alarmDataExport, ws, wwb, services[3]);
alarmDataExport.createHistoryReportByOlt(ws, wwb, service);
// AlarmThreadHis5 his5 = new AlarmThreadHis5(alarmDataExport, ws, wwb, services[4]);
alarmDataExport.createHistoryReportByOnu(ws, wwb, service);
// AlarmThreadHis6 his6 = new AlarmThreadHis6(alarmDataExport, ws, wwb, services[5]);
alarmDataExport.createHistoryReportByOnuDownLine(ws, wwb, service);
// AlarmThreadHis7 his7 = new AlarmThreadHis7(alarmDataExport, ws, wwb, services[6]);
alarmDataExport.createHistoryReportByNeLinked(ws, wwb, service);
// AlarmThreadHis8 his8 = new AlarmThreadHis8(alarmDataExport, ws, wwb, services[7]);
//
// his1.start();
// his2.start();
// his3.start();
// his4.start();
// his5.start();
// his6.start();
// his7.start();
// his8.start();
//
// while(!his1.isOk || !his2.isOk|| !his3.isOk|| !his4.isOk|| !his5.isOk|| !his6.isOk|| !his7.isOk|| !his8.isOk)
// {
// System.out.println("running ..." + new Date().toLocaleString());
// Thread.sleep(6000);
// }
while(!isOK())
{
System.out.println("running ..." + new Date().toLocaleString());
Thread.sleep(6000);
}

for(int i = 0; i < dbOperations.length; i++)
{
dbOperations[i].closeDB();
}

wwb.write();
alarmDataExport.closeBook(hisin, wwb);
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("running:"+ new Date().toLocaleString());
alarmDataExport.printInfoAfterGenHisAlarmReport();
}

private boolean isOK()
{
for(int i = 0; i < his9s.length; i++)
{
if(!his9s[i].isOk)
{
return false;
}
}
return true;
}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值