I am currently trying to figure out how to make asynchronous task at the background if someone reach the rest endpoint. The scenario looks like this:User reaches the endpoint /resourceServer immediately gives him a response with:Status 202, msg={status: started_computation, resource: [actual resource from db], link: /resource/latest}In the same time, server start async method to compute new resource state.After async method ends computing there will be updated resouce  at link /resource/latest which was handled to user at first requestI know how to achive this, but i dont know how to prevent multiple computation. If for example user1 enters endpoint and right after user2 enters endpoint I will have two concurrent methods computing the same resource which is pointles.I would like to have some kind of lock for starting computation only when it is not startedI thought about storing computation state in DB for example: computation=started, computation=finishedAnd before starting async task check the state but is there any other way to do such lock inside backend? I will do it in spring.
Background task in REst service only once at a time
concurrency;spring;asynchronous programming;async;asynchronous