package com.malk.test.dto;

import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * 在同一个类中调用异步方法将无法正常工作(self-invocation);
 */
@Slf4j
@Service
public class Async2Sync {

    @Async
    @Synchronized
    public void addHello() {
        log.info("2");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            log.error(e.getMessage(), e); // 记录错误日志
        }
        log.info("3");
    }

}
