Handling API Message Responses for PDF Analysis

I’m currently processing a task in Java using the Assistant API and threads. The issue I’m facing is that when I send a message, I can’t find a way to wait until the response is generated before returning it. At the moment, I’m using a 10-second timer to check for the response, and if it fails, I try to get the response again after another 10 seconds. However, this approach occasionally fails and adds unnecessary delays.

The task involves analyzing a PDF to extract information, which is why I opted for the Assistant API and threads. Is there an alternative method to handle this without relying on manual timers to check for the response? Specifically, is there a way to wait for the endpoint to return the response without introducing delays? Like chat completions API (im using it to analyze images)