67,513
社区成员
发帖
与我相关
我的任务
分享
class saveDataClass implements Runnable {
private String tableName;//表名
private List<String> columnsTitle;//标题
private ExcelRead er;//自己写的excel对象
private boolean flag;
public saveDataClass(String tableName, List<String> columnsTitle,
ExcelRead er) {
this.tableName = tableName;
this.columnsTitle = columnsTitle;
this.er = er;
this.flag = false;
}
@Override
public void run() {
int start = 1;
int size = 900;
int sheetRowNum = er.getRowNum();//页的行数
int count = sheetRowNum / 900;
if (sheetRowNum % 900 > 0) {
count++;
}
for (int i = 0; i < count; i++) {
int end = start + size;
List<String[]> list = er.readExcelByRowAndDelete(start, end);//获取一段excel中的数据
Thread thread = new Thread(new MyThread(columnsTitle, list, tableName));//开始存数据
thread.start();
start = end;
while(!flag) {
//logger.debug("");这里就有问题,加上打印语句就可以,不加就不行
}
addFlag(false);
}
}
public synchronized void addFlag(boolean flag) {
this.flag = flag;
}
/**
* 进行数据插入的并发类
* @implements Runnable
* @author zcx
*
*/
class MyThread implements Runnable {
List<String> columns;
List<String[]> data;
String tableName;
public MyThread(List<String> columns, List<String[]> data,
String tableName) {
this.columns = columns;
this.data = data;
this.tableName = tableName;
}
@Override
public void run() {
/**
* 数据存入数据库
**/
addFlag(true);
}
}
}