Java how to limit number of threads acting on method

I have java method in my web application doing heavy file operation. The thing is if more than 5 threads come simultaneously(which will come in testing phase) it breaks down i mean it cannot handle heavy traffic.
That’s why i want to handle maximum 5 requests at a time for method if 6th request come it will wait until one of the first 5 finished

public  synchronized void add(int value){
      File a=new File("D:/heavyFile1");
      File b=new File("D:/heavyFile2");
      File c=new File("D:/heavyFile3");
      //operation on file

I have added synchronized keyword but it only handles one request at a time leading to performance issue as every next thred have to wai till it finished. Please help me

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.