implementing counting semaphore using java
<p>I suspect the significant difference between mutex and semaphore is that counting semaphore supports maximum access more than one since mutext only supports at most one access at one time.</p>

<p>But when doing the implementation as follows;</p>

<pre><code>public class countingSemaphore{
 private static final int _MOSTTABLES = 3;  // whatever maximum number
 private static int availtable = _MOSTTABLES;

 public synchronized static void Wait(){  
  while(availtable==0){  
   try{
    wait();    
   }
   catch(InterruptedException e){
    e.printStackTrace();
   }
  }
  availtable--;  
 }

 public synchronized static void Signal(){
  while(availtable==_MOSTTABLES){
   try{
    wait();
   }
   catch(InterruptedException e){
    e.printStackTrace();
   }
  }
  availtable++;  
 }
}
</code></pre>

<p>the problem is the calling of non-static wait() method of object. But, I have to apply synchronization to class instead of instances of objects since accessing is shared among multiple instances. </p>

<p>How to resolve the wait() error? Do we have another method in java or we have to implement wait() ourselves? </p>
