fix:AutoProcess多线程问题
This commit is contained in:
parent
97f4aae3ab
commit
3d5080c1d8
|
@ -156,8 +156,6 @@ public class EmailServiceManager {
|
|||
store = (IMAPStore) session.getStore();
|
||||
//连接
|
||||
store.connect(email.getUsername(),email.getPassword());
|
||||
if (RandomUtil.randomInt(1, 5) == 3)
|
||||
throw new MessagingException();
|
||||
// 解决163普通邮箱无法建立连接问题
|
||||
store.id(IAM);
|
||||
//获取收件箱
|
||||
|
@ -723,8 +721,8 @@ public class EmailServiceManager {
|
|||
try {
|
||||
subject = MimeUtility.decodeText(message.getSubject());
|
||||
receivedDate = message.getReceivedDate();
|
||||
// message.setFlag(Flags.Flag.DELETED,true);
|
||||
// log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
|
||||
message.setFlag(Flags.Flag.DELETED,true);
|
||||
// log.info("EmailServiceManager: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (MessagingException | UnsupportedEncodingException e) {
|
||||
status = EmailLogManager.STATUS_ERROR;
|
||||
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
||||
|
@ -750,6 +748,7 @@ public class EmailServiceManager {
|
|||
if(null != store){
|
||||
store.close();
|
||||
}
|
||||
log.info("EmailServiceManage资源关闭完成.");
|
||||
// for(String messageId : messageIds){
|
||||
// String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
||||
// redisUtil.del(key);
|
||||
|
@ -770,11 +769,11 @@ public class EmailServiceManager {
|
|||
try {
|
||||
String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
||||
int numberKey = redisUtil.get(key) != null? (int) redisUtil.get(key):0;
|
||||
// exist = redisUtil.hasKey(key);
|
||||
// exist = redisUtil.hasKey(key);
|
||||
if(numberKey >= taskProperties.getForceDeletedNumber()){
|
||||
exist = true;
|
||||
log.info("Check: Remove Email:{},receiveTime:{}",message.getSubject(), DateUtils.formatDate(message.getReceivedDate(),"yyyy-MM-dd HH:mm:ss"));
|
||||
// message.setFlag(Flags.Flag.DELETED,true);
|
||||
message.setFlag(Flags.Flag.DELETED,true);
|
||||
redisUtil.del(key);
|
||||
}
|
||||
return exist;
|
||||
|
|
|
@ -47,8 +47,6 @@ public class AutoProcessManager{
|
|||
*/
|
||||
private Map<String,EmailParsingActuator> emailExecThreadMap = new HashMap<>();
|
||||
|
||||
private boolean flag = true;
|
||||
|
||||
/**
|
||||
* 启动自动处理
|
||||
*/
|
||||
|
@ -147,14 +145,9 @@ public class AutoProcessManager{
|
|||
if(!email.isDelFlag()){
|
||||
final EmailServiceManager emailServiceManager = EmailServiceManager.getInstance();
|
||||
emailServiceManager.init(email);
|
||||
/*boolean testFlag = emailServiceManager.testConnectEmailServer();
|
||||
boolean testFlag = emailServiceManager.testConnectEmailServer();
|
||||
if(!testFlag){
|
||||
emails.add(email);
|
||||
}*/
|
||||
int i = RandomUtil.randomInt(1, 5);
|
||||
flag = i == 3;
|
||||
if(flag){
|
||||
emails.add(email);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -238,8 +231,8 @@ public class AutoProcessManager{
|
|||
}else{
|
||||
//如果不包含邮箱id 并且 邮箱处于启用状态 将邮箱对象存入到map中 并将新邮箱标识设置为true
|
||||
if(databaseEmail.getEnabled().equals(SysMailEnableType.ENABLE.getMailEnableType())){
|
||||
// final boolean testFlag = testConnectEmailServer(databaseEmail);
|
||||
if(flag){
|
||||
final boolean testFlag = testConnectEmailServer(databaseEmail);
|
||||
if(testFlag){
|
||||
if (emailExecThreadMap.containsKey(databaseEmail.getId())) {
|
||||
EmailParsingActuator actuator = emailExecThreadMap.get(databaseEmail.getId());
|
||||
actuator.setThreadSleep(false);
|
||||
|
|
|
@ -91,13 +91,11 @@ public class EmailParsingActuator extends Thread{
|
|||
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
||||
for(int i=messages.length-1;i>=0;i--){
|
||||
if (null == messages[i].getHeader("Message-ID")) {
|
||||
System.out.println("Message ID是空值信息!!!!!!!");
|
||||
messages = ArrayUtils.remove(messages, i);
|
||||
continue;
|
||||
}
|
||||
if (!messages[i].isExpunged()){
|
||||
String messageId = ((MimeMessage) messages[i]).getMessageID();
|
||||
System.out.println("正常获取到的Message ID是:"+messageId);
|
||||
final boolean exist = emailServiceManager.check(messages[i],messageId);
|
||||
messageIds.add(messageId);
|
||||
if(exist){
|
||||
|
@ -117,15 +115,14 @@ public class EmailParsingActuator extends Thread{
|
|||
poolExecutor.execute(spectrumParsingActuator);
|
||||
}
|
||||
taskLatch.await();
|
||||
log.info("EmailParsingActuator本次{}封邮件处理完成", messages.length);
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
System.out.println("捕获MessagingException!!!!!!!!");
|
||||
// closeResource();
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
// closeResource();
|
||||
log.error(""+e);
|
||||
log.error("EmailParsingActuator has exception: {}", e.getMessage());
|
||||
log.info("Mail-Parsing线程池资源关闭...");
|
||||
closeResource();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
//清除本批次邮件日志缓存
|
||||
EmailLogManager.getInstance().clear();
|
||||
|
|
Loading…
Reference in New Issue
Block a user