public void StartThread(object ps) { _lastBackupCmonth = null; while (_running == true) { try { var cmonth = Cmonth; if (cmonth == _lastBackupCmonth)//该月已执行 { //Thread.Sleep(ProjDataHelper.CheckMessageInterval); Thread.Sleep(CheckMessageInterval); continue; } var now = DateTime.Now; var backupDay = new DateTime(now.Year, now.Month, BackupDay, BackupHour, BackupMinute, 0); if (backupDay > now || FirstRunTime > now)//未到执行的日期 { Thread.Sleep(PFTaskHelper.CheckMessageInterval); continue; } if (!CanDoAction(cmonth, this)) { Thread.Sleep(CheckMessageInterval); continue; } _lastBackupCmonth = cmonth; _nextRunTime = backupDay.AddMonths(1); PFDataHelper.WriteLog(string.Format("任务{0}开始执行,月份为:{1}", HashId, cmonth));//调用这个方法来写这个值并不好,因为每天都单独一个txt的 try { DoAction(cmonth, this); PFDataHelper.WriteLog(string.Format("任务{0}执行完毕,月份为:{1}", HashId, cmonth)); } catch (Exception e) { PFDataHelper.WriteError(e); } GC.Collect();//一定要有句,否则SendMobileMessage里面的所有List会使内存越来越高 } catch (Exception e) { PFDataHelper.WriteError(e); } } }
public void StartThread(object ps) { _lastBackupCDay = null; _lastBackupTime = null; while (_running == true) { try { var cDay = CDay; if (cDay == _lastBackupCDay)//该日已执行 { Thread.Sleep(PFTaskHelper.CheckMessageInterval); continue; } var now = DateTime.Now; var backupDay = new DateTime(now.Year, now.Month, now.Day, BackupHour, BackupMinute, 0); if (backupDay > now || FirstRunTime > now)//未到执行的时间 { Thread.Sleep(PFTaskHelper.CheckMessageInterval); continue; } _lastBackupCDay = cDay; _nextRunTime = backupDay.AddDays(1); PFDataHelper.WriteLog(string.Format("任务{0}开始执行,日期为:{1}", HashId, cDay)); try { DoAction(cDay, _lastBackupTime, this); _lastBackupTime = now; PFDataHelper.WriteLog(string.Format("任务{0}执行完毕,日期为:{1}", HashId, cDay)); } catch (Exception e) { PFDataHelper.WriteError(e); } GC.Collect();//一定要有句,否则SendMobileMessage里面的所有List会使内存越来越高 } catch (Exception e) { PFDataHelper.WriteError(e); } } }
//private Properties GetAliMqProperties() { // Properties properties = new Properties(); // if(!PFDataHelper.StringIsNullOrWhiteSpace(_mqConfig.getGroupId())) { // properties.put(PropertyKeyConst.GROUP_ID, _mqConfig.getGroupId()); // } // if(!PFDataHelper.StringIsNullOrWhiteSpace(_mqConfig.getNameSrvAddr())) { // properties.put(PropertyKeyConst.NAMESRV_ADDR, _mqConfig.getNameSrvAddr()); // } // // 设置 TCP 接入域名(此处以公共云生产环境为例) // if(!PFDataHelper.StringIsNullOrWhiteSpace(_mqConfig.getOnsAddr())) { // properties.put(PropertyKeyConst.ONSAddr, _mqConfig.getOnsAddr()); // } // // AccessKey 阿里云身份验证,在阿里云服务器管理控制台创建 // properties.put(PropertyKeyConst.AccessKey,_mqConfig.getAccessKey()); // // SecretKey 阿里云身份验证,在阿里云服务器管理控制台创建 // properties.put(PropertyKeyConst.SecretKey, _mqConfig.getSecretKey()); // //设置发送超时时间,单位毫秒 // properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "3000"); // if("CLUSTERING".equals(_mqConfig.getMessageModel())) { // properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING); // }else if("BROADCASTING".equals(_mqConfig.getMessageModel())) { // properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING); // } // return properties; //} private void WriteLog(String logMsg) { PFDataHelper.WriteLog(logMsg); //System.out.println(logMsg); }