今天碰见一个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";
}
}各位看看,那里出问题啦..