优化代码:新增销毁方法,在程序优雅退出后主动shutdown线程池,从而触发InterruptedException异常,break出循环

master
xzxiaoshan 4 days ago
parent bee9e24085
commit 4fc4859666

@ -9,7 +9,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
*
@ -31,12 +33,24 @@ public class MessageReceipt {
for (ReceiptMessageStater receiptMessageStater : receiptMessageStaterList) {
//receiptMessageStater.start();
}
Thread.sleep(2000);
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException ex) {
log.error("MessageReceipt#init interrupted: {}", ex.getMessage());
Thread.currentThread().interrupt();
break;
} catch (Exception e) {
log.error("MessageReceipt#init fail:{}", Throwables.getStackTraceAsString(e));
Thread.currentThread().interrupt();
}
}
});
}
/**
*
*/
@PreDestroy
public void onDestroy() {
SupportThreadPoolConfig.getPendingSingleThreadPool().shutdown();
}
}

Loading…
Cancel
Save