【发布时间】:2016-08-30 09:41:50
【问题描述】:
如何为 Spring AOP Aspect 提供超时执行?
MyAspect 的 logger 方法的执行时间不应超过 30 秒,否则我想停止该方法的执行。我该怎么做?
MyAspect 代码:
@Aspect
@Component
public class MyAspect {
@Autowired
private myService myService;
@AfterReturning(pointcut = "execution(* xxxxx*(..))", returning = "paramOut")
public void logger(final JoinPoint jp, Object paramOut){
Event event = (Event) paramOut;
myService.save(event);
}
}
myService 接口:
public interface myService {
void save(Event event);
}
myServiceImpl :
@Service
@Transactional
public class myServiceImpl implements myService {
@PersistenceContext
private EntityManager entityManager;
@Override
public void save(Event event) {
entityManager.persist(event);
}
}
【问题讨论】:
-
请将您的代码粘贴到问题中
-
@LajosArpad 完成!,我想要做的是:避免我的 Aspect 的记录器方法需要无限时间执行。谢谢
-
我建议使用异步日志记录,那么它可能需要多长时间。
标签: java spring spring-aop spring-async