Skip to content

Initial commit.#244

Open
Wojtek-A-JAVA wants to merge 2 commits into
mate-academy:mainfrom
Wojtek-A-JAVA:main
Open

Initial commit.#244
Wojtek-A-JAVA wants to merge 2 commits into
mate-academy:mainfrom
Wojtek-A-JAVA:main

Conversation

@Wojtek-A-JAVA

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Good job setting up the asynchronous execution flow with CompletableFuture and an ExecutorService. However, this requires changes because the two central requirements of the task have not been implemented: caching and a simulated processing delay.

In your AsyncRequestProcessor class, you need to:

  1. Add Caching Logic: Introduce a ConcurrentHashMap to store UserData results. Before creating a new UserData object, your processRequest method must first check this map. If the data for a userId exists, it should be returned from the cache immediately.
  2. Simulate a Delay: Inside the CompletableFuture.supplyAsync block, add a delay using Thread.sleep() to simulate a long-running operation. This is crucial for demonstrating the benefit of the caching mechanism.

Once these two features are implemented, your solution will meet all the core requirements. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +14 to +15
UserData userData = new UserData(userId, "Details for " + userId);
return CompletableFuture.supplyAsync(() -> userData, executor);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is missing the core caching logic and the simulated processing delay. According to the requirements, you should:

  1. Add a ConcurrentHashMap cache as a field in this class.
  2. Before creating a new UserData object, check if the data for the given userId is already in the cache. If it is, return the cached value directly (wrapped in a completed CompletableFuture).
  3. Add a simulated delay inside the supplyAsync task to mimic a real-world, long-running operation.
  4. After successfully creating a new UserData object, store it in the cache before returning it.

public static void main(String[] args) {
// Feel free to play with AsyncRequestProcessor in this main method if you want
ExecutorService executor = null; // Provide implementation that fits your needs
public static void main(String[] args) throws InterruptedException {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this method correctly sets up and runs the asynchronous tasks, the overall application behavior will not meet the requirements. The AsyncRequestProcessor class that is used here is missing the mandatory caching implementation. As a result, repeated requests for the same userId will be fully processed every time instead of being served from the cache.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this iteration! You have successfully addressed all the previous feedback and met all the requirements of the task. The caching logic with ConcurrentHashMap is correctly implemented, and the use of CompletableFuture for asynchronous processing is spot on.

I have left one minor suggestion in src/main/java/mate/academy/Main.java regarding an unnecessary Thread.sleep(). This is just a small point for improvement and doesn't block the approval.

Your solution is now complete and correct, so I am approving your submission. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

ExecutorService executor = Executors.newFixedThreadPool(2);
executor.execute(() -> System.out.println("Executor started"));

Thread.sleep(2000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Thread.sleep(2000) call introduces an unnecessary 2-second delay at the start of the program. The ExecutorService is ready for use immediately after creation, so this wait isn't needed. You can safely remove this line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants