I have a backend app in Java that process Images and PDFs. When I process the PDF the app needs a few seconds so there is not problem. When I need to process image, in order to get the best result I run other processes that takes time (like 1 or 2 minutes) and the idea is that the user can process several documents at the same time, so it could take really long!
So in order to avoid the user to keep waiting for the app to finish the process, I implemented Thread (Runnable) in order to generate a new Thread for each document. But as the process is the same (after the image process), the method is share between both file types.
So I want to generate new Thread, but for the PDF files, I want that the user do not notice any change, I mean, that the app process the file and return a response to the front end. But for the image, I wanted to create new thread and keep working on the background while the user see a message saying that the files are being processed, and he will be notify when the process ends.
So when I was checking this answer: How can I pass a parameter to a Java Thread?
But then instread of:
Runnable r = new MyRunnable(param_value);
Thread t = new Thread(r).start();
I want to have like
if(type = "PDF"){
t.join();
response = getSomeResponse();
}
else{
//ShowMessage
}
So, is there a way to work with threads, and for some cases wait for it to finish and get a result and in some cases just let them work while the main thread is complete and I can inform the user that he will be notify at the end?