title: Java how to limit number of threads acting on method
body: <p>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.</p>
  
  <p>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</p>
  
  <pre><code>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
    }
  </code></pre>
  
  <p>I have added synchronized keyword but it only handles one request at a time leading to performance issue as every next thread have to wait till it is finished. Please help me.</p>