I'm currently developing a web application using spring boot and I have a problem in the service layer.
I have a heavy method on my service layer. If multiple users call that same service, the applications stops due to low memory. So I want to limit the no of parallel running threads of that method only. So far I have come out with using synchronized on that method. But it will limit it to single threaded method.
@Service
public class DocumentService{
private synchronized void doReplacement(){
//should have limited no of multi threads (eg. 3)
}
private void normalMethod(){
//no restrictions
}
}
What can I do to achieve this task. Any help would be appreciated.