0

I have a method which recieves a file and this file then gets processed. But the processing takes quite long so I wanna do that in the background and just tell the user that this file will be processed now. But my requirement is that this task can only get called when the call before has finished. So the user then should get an error that he must wait.

I know I could queue the processing but I want to keep it simple.

So how can I do that? And would there be some method to request if the this task is finished or not so the client can refresh a status and fetch a flag if the task is finished or not?

JuNe
  • 1,911
  • 9
  • 28

1 Answers1

1

In your async method set some shared data structure “taskProcessing” flag to true and set to false at the end. And return an error when task is called again and taskProcessing is true. Simple.

Strelok
  • 50,229
  • 9
  • 102
  • 115
  • Yes, I solved it by setting an `AtomicBoolean` as a flag and limited my thread pool to 1. – JuNe Dec 11 '19 at 11:55