home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- class ObjectPool {
- Object[] freePool;
- int freePoolMaxLength;
- int freePoolNextSlot;
- Class objectClass;
- int allocSaved;
- int allocDone;
- int maxCapacity;
-
- public ObjectPool(String var1) {
- this(var1, 32);
- }
-
- public ObjectPool(String var1, int var2) {
- this.freePool = new Object[1];
- this.freePoolMaxLength = 1;
- this.freePoolNextSlot = 0;
-
- try {
- this.objectClass = Class.forName(var1);
- } catch (ClassNotFoundException var3) {
- System.out.println("ObjectPool cannot find class " + var1);
- }
-
- this.allocSaved = 0;
- this.allocDone = 0;
- this.maxCapacity = var2;
- }
-
- public Object allocateObject() {
- Object var1 = null;
- synchronized(this){}
-
- try {
- if (this.freePoolNextSlot > 0) {
- --this.freePoolNextSlot;
- var1 = this.freePool[this.freePoolNextSlot];
- }
- } catch (Throwable var8) {
- throw var8;
- }
-
- if (var1 == null) {
- ++this.allocDone;
-
- try {
- var1 = this.objectClass.newInstance();
- } catch (InstantiationException var6) {
- System.out.println("Cannot instantiate instance of class " + this.objectClass);
- } catch (IllegalAccessException var7) {
- System.out.println("Cannot instantiate instance of class. Illegal." + this.objectClass);
- }
- } else {
- ++this.allocSaved;
- }
-
- return var1;
- }
-
- public void recycleObject(Object var1) {
- synchronized(this){}
-
- try {
- if (this.freePoolMaxLength < this.maxCapacity) {
- if (this.freePoolNextSlot == this.freePoolMaxLength) {
- Object[] var4 = new Object[this.freePoolMaxLength * 2];
- System.arraycopy(this.freePool, 0, var4, 0, this.freePoolMaxLength);
- this.freePool = var4;
- this.freePoolMaxLength *= 2;
- }
-
- this.freePool[this.freePoolNextSlot++] = var1;
- }
- } catch (Throwable var6) {
- throw var6;
- }
-
- }
-
- protected void finalize() {
- for(int var1 = 0; var1 < this.freePoolNextSlot; ++var1) {
- this.freePool[var1] = null;
- }
-
- this.freePool = null;
- }
-
- public String toString() {
- return "Object pool for class " + this.objectClass + " has " + this.freePoolNextSlot + " instances." + " " + this.allocSaved + " allocations avoided allocation performed:" + this.allocDone;
- }
- }
-