Skip to content

Commit

Permalink
🐛 Bug/319 멀티스레드로 인한 deadlock 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanvp committed Feb 20, 2024
1 parent 6785935 commit 12e88d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -949,40 +949,28 @@ public TestRecipe testCreate(RecipeRequestDto.CreateRecipeDto request, Multipart
@Override
@Transactional(readOnly = false)
public TestRecipe testCreateWithImageUrl(RecipeRequestDto.CreateRecipeWithImageUrlDto request){
TestRecipe buildRecipe = RecipeConverter.toTestRecipeWithImageUrl(request);
testRecipeRepository.save(buildRecipe);

CompletableFuture<TestRecipe> savedRecipeFuture = CompletableFuture.supplyAsync(() ->{
TestRecipe buildRecipe = null;
buildRecipe = RecipeConverter.toTestRecipeWithImageUrl(request);

return testRecipeRepository.save(buildRecipe);
});

savedRecipeFuture.thenAccept(recipe -> {
RecipeConverter.toTestRecipeCategory(request.getCategoryId(),recipe).join().stream()
.map(categoryMapping -> testRecipeCategoryMappingRepository.save(categoryMapping))
.collect(Collectors.toList())
.stream()
.map(categoryMapping -> categoryMapping.setRecipe(recipe));
});

RecipeConverter.toTestRecipeCategory(request.getCategoryId(),buildRecipe).join().stream()
.map(categoryMapping -> testRecipeCategoryMappingRepository.save(categoryMapping))
.collect(Collectors.toList())
.stream()
.map(categoryMapping -> categoryMapping.setRecipe(buildRecipe));

savedRecipeFuture.thenAccept(recipe -> {
RecipeConverter.toTestStepWithImageUrl(request, recipe).join().stream()
.map(step -> testStepRepository.save(step))
.collect(Collectors.toList())
.stream()
.map(step -> step.setRecipe(recipe));
});
RecipeConverter.toTestStepWithImageUrl(request, buildRecipe).join().stream()
.map(step -> testStepRepository.save(step))
.collect(Collectors.toList())
.stream()
.map(step -> step.setRecipe(buildRecipe));

savedRecipeFuture.thenAccept(recipe -> {
RecipeConverter.toTestIngredientWithImageUrl(request, recipe).join().stream()
.map(ingredient -> testIngredientRepository.save(ingredient))
.collect(Collectors.toList())
.stream()
.map(ingredient -> ingredient.setRecipe(recipe));
});
RecipeConverter.toTestIngredientWithImageUrl(request, buildRecipe).join().stream()
.map(ingredient -> testIngredientRepository.save(ingredient))
.collect(Collectors.toList())
.stream()
.map(ingredient -> ingredient.setRecipe(buildRecipe));

return savedRecipeFuture.join();
return buildRecipe;
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ spring:
username: ${aws.db.username}
password: ${aws.db.password}
url: ${aws.db.url}
# hikari:
# leak-detection-threshold: 3000
output:
ansi:
enabled: always
Expand Down Expand Up @@ -118,6 +120,9 @@ spring:
username: ${aws.db.username}
password: ${aws.db.password}
url: ${aws.db.url}
hikari:
#leak-detection-threshold: 2000
#maximum-pool-size: 1
output:
ansi:
enabled: always
Expand Down Expand Up @@ -206,6 +211,11 @@ fcm:
url: ${FCM_URL}
project-num: ${FCM_PROJECT_NUMBER}

logging:
level:
com.zaxxer.hikari.HikariConfig: DEBUG
com.zaxxer.hikari: TRACE

---
spring:
config:
Expand Down

0 comments on commit 12e88d6

Please sign in to comment.