Skip to content

Commit

Permalink
Merge pull request #36 from Anant/feature/ItemsByIdParallel
Browse files Browse the repository at this point in the history
Add POST method to items and Increase Queue Size
  • Loading branch information
anomnaco authored Sep 13, 2024
2 parents 655b0aa + 4b7aac4 commit daf5c0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public TaskExecutor asyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(corePoolSize * 4);
executor.setQueueCapacity(corePoolSize * 4);
executor.setQueueCapacity(corePoolSize * 4096);
executor.setThreadNamePrefix("AsyncThread-");
executor.initialize();
return executor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -43,4 +45,19 @@ public ResponseEntity<?> getItemsParallel(@RequestParam final List<String> ids)
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@Operation(description = "Post method to fetch Item data in parallel based on a list of item IDs")
@PostMapping
public ResponseEntity<?> postItemsParallel(@Parameter @RequestBody final List<String> ids) {
try {
final List<ItemModelResponse> itemModels = ids.stream()
.map(itemService::getItemsByIdParallel)
.toList().stream().map(CompletableFuture::join).collect(Collectors.toList());
return new ResponseEntity<>(itemModels, HttpStatus.OK);
} catch (Exception ex) {
final Map<String, String> message = new HashMap<>();
message.put("message", ex.getLocalizedMessage());
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

0 comments on commit daf5c0f

Please sign in to comment.