fix:增加catch中exception写入log日志
This commit is contained in:
parent
64a98bd4ea
commit
f6b963145f
|
@ -1,8 +1,6 @@
|
||||||
package org.jeecg.common.email;
|
package org.jeecg.common.email;
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.sun.mail.imap.IMAPStore;
|
import com.sun.mail.imap.IMAPStore;
|
||||||
|
@ -32,7 +30,6 @@ import java.io.*;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -127,7 +124,7 @@ public class EmailServiceManager {
|
||||||
/**
|
/**
|
||||||
* 接收邮件
|
* 接收邮件
|
||||||
*/
|
*/
|
||||||
public Message[] receiveMail() throws MessagingException {
|
public Message[] receiveMail() throws Exception {
|
||||||
String status = EmailLogManager.STATUS_SUCCESS;
|
String status = EmailLogManager.STATUS_SUCCESS;
|
||||||
try{
|
try{
|
||||||
//配置邮件服务属性
|
//配置邮件服务属性
|
||||||
|
@ -179,6 +176,7 @@ public class EmailServiceManager {
|
||||||
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
|
return o1.getReceivedDate().compareTo(o2.getReceivedDate());
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
@ -188,7 +186,7 @@ public class EmailServiceManager {
|
||||||
return Arrays.copyOfRange(messages,0,this.receiveNum-1);
|
return Arrays.copyOfRange(messages,0,this.receiveNum-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (MessagingException e){
|
} catch (Exception e){
|
||||||
status = EmailLogManager.STATUS_ERROR;
|
status = EmailLogManager.STATUS_ERROR;
|
||||||
log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage());
|
log.error("Email connection is abnormal, account is {}, service is {},the reason is {}.",email.getName(),email.getEmailServerAddress(),e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -729,6 +727,7 @@ public class EmailServiceManager {
|
||||||
status = EmailLogManager.STATUS_ERROR;
|
status = EmailLogManager.STATUS_ERROR;
|
||||||
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
log.error("Email deletion failed, the subject of the email is :{}, the reason is :{}.",subject,e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}finally {
|
}finally {
|
||||||
EmailLogEvent removeEvent = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.DELETEID,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"));
|
EmailLogEvent removeEvent = new EmailLogEvent(batchesCounter,Thread.currentThread().getId(),EmailLogManager.GS_TYPE_GET,status,EmailLogManager.DELETEID,subject,DateUtils.formatDate(receivedDate,"yyyy-MM-dd HH:mm:ss:SSS"));
|
||||||
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),removeEvent);
|
EmailLogManager.getInstance().offer(Thread.currentThread().getId(),removeEvent);
|
||||||
|
@ -750,7 +749,7 @@ public class EmailServiceManager {
|
||||||
if(null != store){
|
if(null != store){
|
||||||
store.close();
|
store.close();
|
||||||
}
|
}
|
||||||
log.info("EmailServiceManage资源关闭完成.");
|
log.info(Thread.currentThread().getName() + ",EmailServiceManage资源关闭完成.");
|
||||||
// for(String messageId : messageIds){
|
// for(String messageId : messageIds){
|
||||||
// String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
// String key = RedisConstant.EMAIL_MSG_ID+StringConstant.COLON+messageId;
|
||||||
// redisUtil.del(key);
|
// redisUtil.del(key);
|
||||||
|
@ -758,6 +757,7 @@ public class EmailServiceManager {
|
||||||
} catch (MessagingException e) {
|
} catch (MessagingException e) {
|
||||||
log.error("Email closure failed, email address is: {}, reason is: {}",email.getUsername(),e.getMessage());
|
log.error("Email closure failed, email address is: {}, reason is: {}",email.getUsername(),e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.jeecg.modules;
|
package org.jeecg.modules;
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
import org.jeecg.common.constant.RedisConstant;
|
||||||
|
@ -120,6 +119,7 @@ public class AutoProcessManager{
|
||||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ public class AutoProcessManager{
|
||||||
//捕获异常不处理保障线程异常不退出
|
//捕获异常不处理保障线程异常不退出
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
long sleepTime = taskProperties.getMonitoringMailCommStatusCycle() - (end-start);
|
long sleepTime = taskProperties.getMonitoringMailCommStatusCycle() - (end-start);
|
||||||
|
@ -178,6 +179,7 @@ public class AutoProcessManager{
|
||||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,6 +253,7 @@ public class AutoProcessManager{
|
||||||
//捕获异常不处理保障线程异常不退出
|
//捕获异常不处理保障线程异常不退出
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
long sleepTime = taskProperties.getMonitoringMailDataCycle() - (end-start);
|
long sleepTime = taskProperties.getMonitoringMailDataCycle() - (end-start);
|
||||||
|
@ -260,6 +263,7 @@ public class AutoProcessManager{
|
||||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,6 +308,7 @@ public class AutoProcessManager{
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}finally {
|
}finally {
|
||||||
if(emailExecThread.getState() != State.TERMINATED && emailExecThread.isStop()){
|
if(emailExecThread.getState() != State.TERMINATED && emailExecThread.isStop()){
|
||||||
final long nowTime = System.currentTimeMillis();
|
final long nowTime = System.currentTimeMillis();
|
||||||
|
@ -325,6 +330,7 @@ public class AutoProcessManager{
|
||||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,8 @@ public class EmailParsingActuator extends Thread{
|
||||||
List<String> messageIds = new ArrayList<>();
|
List<String> messageIds = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Message[] messages = emailServiceManager.receiveMail();
|
Message[] messages = emailServiceManager.receiveMail();
|
||||||
|
log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), ArrayUtils.isEmpty(messages) ? 0 : messages.length);
|
||||||
if(ArrayUtils.isNotEmpty(messages)){
|
if(ArrayUtils.isNotEmpty(messages)){
|
||||||
log.info("EmailParsingActuator本次{}获取邮件数量为:{}", Thread.currentThread().getName(), messages.length);
|
|
||||||
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
//检验获取的邮件是否在之前删除失败列表中,若在直接调用邮件API删除,并且此次数组里元素也删除
|
||||||
for(int i=messages.length-1;i>=0;i--){
|
for(int i=messages.length-1;i>=0;i--){
|
||||||
if (null == messages[i].getHeader("Message-ID")) {
|
if (null == messages[i].getHeader("Message-ID")) {
|
||||||
|
@ -122,6 +122,7 @@ public class EmailParsingActuator extends Thread{
|
||||||
log.error("EmailParsingActuator has exception: {}", e.getMessage());
|
log.error("EmailParsingActuator has exception: {}", e.getMessage());
|
||||||
log.info("Mail-Parsing线程池资源关闭...");
|
log.info("Mail-Parsing线程池资源关闭...");
|
||||||
closeResource();
|
closeResource();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
//清除本批次邮件日志缓存
|
//清除本批次邮件日志缓存
|
||||||
|
@ -142,6 +143,8 @@ public class EmailParsingActuator extends Thread{
|
||||||
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
TimeUnit.MILLISECONDS.sleep(sleepTime);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user