| 12345678910111213141516171819202122232425262728293031323334 |
- package cn.seecoder.paas.util;
- import lombok.extern.apachecommons.CommonsLog;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Component;
- @Component
- @CommonsLog
- public class AsyncWrapper {
- @FunctionalInterface
- public interface Method {
- void invoke() throws Exception;
- }
- @Async("asyncExecutor")
- public void asyncInvoke(Method method) {
- try {
- method.invoke();
- } catch (Exception e) {
- log.error("进行异步调用时发生异常[" + e.getClass() + "]:" + e.getMessage());
- }
- }
- @Async("asyncExecutor")
- public void asyncInvoke(Method method, long delay) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- asyncInvoke(method);
- }
- }
|