Home > Back-end >  Java made of timer timer synchronous data task, just deployed a data synchronization, the next day w
Java made of timer timer synchronous data task, just deployed a data synchronization, the next day w

Time:11-01

A timing synchronization data using the timer to do tasks, the synchronization time, but the next day the timing task synchronization multiple times, causing data repeat this because what
Specific code is as follows:
Public void init () throws ServletException {
Long daySpan=24 * 60 * 60 * 1000;
Final SimpleDateFormat SDF=new SimpleDateFormat (" yyyy - MM - dd 04:00:00 ");
The Date startTime=null;
Try {
StartTime=new SimpleDateFormat (" MM - dd yyyy - HH: MM: ss "). The parse (SDF) format (new Date ()));
} the catch (ParseException e) {
e.printStackTrace();
}

If (System. CurrentTimeMillis () & gt; StartTime. GetTime ()) {
StartTime=new Date (startTime getTime () + daySpan);
}

The Timer Timer=new Timer (" synchronous worker, department information ");
TimerTask task=new TimerTask () {
Public void the run () {
System. Out.println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- batchStart!! ");
The Connection conn=null;
Try {
Conn=DBUtil. GetConnection ();
//open the synchronous
T_systemDAO T_systemDAO=new T_systemDAOImpl (conn);
T_systemEntity T_systemEntity=t_systemDAO. SelectEntityForUpdate (" where trcode='TT15' ");
Integer nowDate=AssetManageUtil. GetDate ();
If (nowDate==t_systemEntity. GetTrdate ()) {
//has been processing is complete, without any processing
} else {
////delete history log
//DeleteHistoryLogUtil deleteHistoryLog ();
////synchronization personnel
//ToHrService ToHrService=new ToHrService ();
//toHrService getNoTrlStaff ();
//toHrService getAllBosses ();
//toHrService=null;
//the return to do
BatchWaitThings waitThings=new BatchWaitThings ();
WaitThings. RevertOfficeWaitThings ();
//quality assurance to do
WaitThings. GuaranteWaitThings ();
ToEmisService emiseService=new ToEmisService ();
Try {
The debug (" into the synchronous department information -- -- -- -- -- - ");
EmiseService. SynEmisDepInfo ();
The log. The debug (" into the synchronous personnel information -- -- -- -- -- - ");
EmiseService. SynEmisStaffInfo ();
} the catch (Exception e) {
System. The out. Println (" synchronous department, worker problems ");
e.printStackTrace();
}
If (EnvironmentInitServet. Properties. GetProperty (" connMark "). EqualsIgnoreCase (" Y ")) {
The File f=new File (EnvironmentInitServet. Properties. GetProperty (" connLogPath "));
If (f.e xists ()) {
F.d elete ();
}
Try {
F. reateNewFile ();
} the catch (IOException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}
}
//remove the log object
LogPool. RemoveAll ();

T_systemEntity. SetTrdate (nowDate);
T_systemDAO. Update (t_systemEntity, "where trcode='TT15'");
DBUtil.com MIT (conn);
}
} the catch (Exception e) {
Try {
DBUtil. Rollback (conn);
{} catch Exception (e2)
e2.printStackTrace();
}
e.printStackTrace();
} the finally {
DBUtil. Close (conn);
}
}
};
Timer. ScheduleAtFixedRate (task, startTime, daySpan);
}
  • Related