今天碰见一个Quartz定时调用任务的奇怪问题,百思不得其解,发出来各位网友看看有什么问题项目需求:每天早上9:00分读取一个.txt文件(大小2MB左右),分析数据并插入数据库,txt文件大约3万行,每天读取的.txt文件内容是不一样的,文件名以昨天的日期为名,如:6月23日早上读取20100622.txt这个文件。文件都存在。问题描述:使用Quartz进行作业调度。tomcat启动之后的第一天执行没有问题。第二天就不执行啦。1.quartz_job.xml文件配置如下:
<job>
<job-detail>
<name>Job_CheckFile</name>
<group>DEFAULT</group>
<job-class>com.biz.CheckFileJob</job-class>
</job-detail>
<trigger>
<cron>
<name>Trigger_File</name>
<group>DEFAULT</group>
<job-name>Job_CheckFile</job-name>
<job-group>DEFAULT</job-group>
<cron-expression>0 0 9 * * ?</cron-expression>
</cron>
</trigger>
</job>2.CheckFileJob类
public class CheckFileJob implements Job {
public CheckFileJob(){
}
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
JobBiz.checkFile(jobDataMap);
}}3.JobBiz 类
public class JobBiz {
public static void checkFile(JobDataMap jobDataMap){
String fname = Common.getYesterdayFile();
File file = new File("D:\\"+fname);
Connection conn = ConnectionManager.getConnection();
String sql = "insert into info(place1,place2) values(?,?)";
PreparedStatement psmt = null;
try {
conn.setAutoCommit(false);
psmt = conn.prepareStatement(sql);
if(file.exists() && file.isFile()){
try {
FileReader fr = new FileReader(file);
BufferedReader reader = new BufferedReader(fr);
String line = reader.readLine();
int count = 1;
while(line!=null){
String[] strs = line.split("\t");
psmt.setString(1, strs[0]);
psmt.setString(2, strs[1]);
psmt.addBatch();
if(count % 5000 == 0){
psmt.executeBatch();
conn.commit();
psmt.clearBatch();
}
count++;
line = reader.readLine();
}
psmt.executeBatch();
conn.commit();
psmt.clearBatch();
reader.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}//end if
} catch (SQLException e1) {
e1.printStackTrace();
}finally{
ConnectionManager.free(conn, psmt);
}
}
}4.获取文件名的类
public class Common{
public static String getYesterdayFile(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
Date date = cal.getTime();
return sdf.format(date)+".txt";
}
}各位看看,那里出问题啦..
<job>
<job-detail>
<name>Job_CheckFile</name>
<group>DEFAULT</group>
<job-class>com.biz.CheckFileJob</job-class>
</job-detail>
<trigger>
<cron>
<name>Trigger_File</name>
<group>DEFAULT</group>
<job-name>Job_CheckFile</job-name>
<job-group>DEFAULT</job-group>
<cron-expression>0 0 9 * * ?</cron-expression>
</cron>
</trigger>
</job>2.CheckFileJob类
public class CheckFileJob implements Job {
public CheckFileJob(){
}
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
JobBiz.checkFile(jobDataMap);
}}3.JobBiz 类
public class JobBiz {
public static void checkFile(JobDataMap jobDataMap){
String fname = Common.getYesterdayFile();
File file = new File("D:\\"+fname);
Connection conn = ConnectionManager.getConnection();
String sql = "insert into info(place1,place2) values(?,?)";
PreparedStatement psmt = null;
try {
conn.setAutoCommit(false);
psmt = conn.prepareStatement(sql);
if(file.exists() && file.isFile()){
try {
FileReader fr = new FileReader(file);
BufferedReader reader = new BufferedReader(fr);
String line = reader.readLine();
int count = 1;
while(line!=null){
String[] strs = line.split("\t");
psmt.setString(1, strs[0]);
psmt.setString(2, strs[1]);
psmt.addBatch();
if(count % 5000 == 0){
psmt.executeBatch();
conn.commit();
psmt.clearBatch();
}
count++;
line = reader.readLine();
}
psmt.executeBatch();
conn.commit();
psmt.clearBatch();
reader.close();
fr.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}//end if
} catch (SQLException e1) {
e1.printStackTrace();
}finally{
ConnectionManager.free(conn, psmt);
}
}
}4.获取文件名的类
public class Common{
public static String getYesterdayFile(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
Date date = cal.getTime();
return sdf.format(date)+".txt";
}
}各位看看,那里出问题啦..
解决方案 »
- dialog如何根据不同操作系统设置不同的高
- 帮看一个jdbc获取oracle存储过程自定义类型的问题。。。。
- 关于checkbox的问题..求解答..求代码~~谢谢
- 关于ajax乱码问题?
- struts1.2 在action 跳转后form中的值没有,导致分页失败
- 求救:Hibernate的问题:stackoverflowerror
- 用aspectj如何一次性向多个类添加同一方法
- servlet向jsp传递参数为什么会是NULL的(Vector)
- 有关在struts标签中嵌套变量的问题,急!!
- 用JDBC连接MySQL数据库的问题...笨啊...
- java判读unix下的文件带中文报不存在
- 用JAVA SWING写了个小应用,怎么改启动后的进程名呢?
如果没报错,估计quartz任务停止了,要么服务停止,要么trigger有问题
系统在服务器上放着,怎么看报错啊??是要看tomcat的日志吗?