Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 5 package com.teamkonzept.db; 6 7 import com.teamkonzept.lib.*; 8 import org.apache.log4j.Category; 9 10 14 public class TKLimiter { 15 16 private static final Category CAT = Category.getInstance(TKLimiter.class); 17 public int limit; 18 public int used; 19 public int pending; 20 21 public TKLimiter() 22 { 23 limit = 0; 24 used = 0; 25 pending = 0; 26 } 27 28 public TKLimiter( int aLimit ) 29 { 30 limit = aLimit; 31 used = 0; 32 pending = 0; 33 } 34 35 public synchronized void newLimit( int aLimit ) 36 { 37 limit = aLimit; 38 if ((limit <= 0) && (pending > 0)) 39 { 40 notifyAll(); 41 } 42 else if ((used < limit) && (pending > 0)) 43 { 44 notify(); 45 } 46 } 47 48 public synchronized void take() 49 { 50 pending++; 51 while ((used >= limit) && (limit > 0)) { 52 53 try { 54 wait(); 55 } 56 catch( InterruptedException ie ) { CAT.error(ie);} 57 } 58 59 pending--; 60 used++; 61 } 62 63 public synchronized void free() 64 { 65 used--; 66 if ((limit <= 0) && (pending > 0)) 67 { 68 notifyAll(); 69 } 70 else if ((used < limit) && (pending > 0)) 71 { 72 notify(); 73 } 74 } 75 } 76 77
| Popular Tags
|