-
-
Save b1a9id/bb5059c20430bab9802a57b6fbb63873 to your computer and use it in GitHub Desktop.
asyncのAsyncServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.retry.annotation.Recover; | |
import org.springframework.retry.annotation.Retryable; | |
import org.springframework.scheduling.annotation.Async; | |
import org.springframework.stereotype.Service; | |
import com.b1a9idps.springasyncdemo.dto.request.AsyncRequest; | |
import com.b1a9idps.springasyncdemo.exception.FailedFileUploadException; | |
import com.b1a9idps.springasyncdemo.infrastructure.FileService; | |
import com.b1a9idps.springasyncdemo.service.AsyncService; | |
@Service | |
public class AsyncServiceImpl implements AsyncService { | |
private static final Logger LOGGER = LoggerFactory.getLogger(AsyncServiceImpl.class); | |
private final FileService fileService; | |
public AsyncServiceImpl(FileService fileService) { | |
this.fileService = fileService; | |
} | |
@Override | |
@Retryable(value = FailedFileUploadException.class, recover = "saveRecover") | |
@Async | |
public void save(AsyncRequest request) { | |
LOGGER.info("Start Async processing.(number = " + request.getNumber() + ")"); | |
try { | |
Thread.sleep(500); | |
fileService.upload(); | |
} catch (InterruptedException e) { | |
LOGGER.error("thrown InterruptedException."); | |
} | |
LOGGER.info("End Async processing.(number = " + request.getNumber() + ")"); | |
} | |
@Recover | |
private void saveRecover(FailedFileUploadException e, AsyncRequest request) { | |
LOGGER.error("failed to upload file(number = " + request.getNumber() + ")", e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment