Menu

#2 GenericPool uses default constructor

open
nobody
None
5
2001-05-25
2001-05-25
No

The GenericPool uses default constructor for the first
object and uses the parameterized version after that.

If you first call

public GenericPool(GenericPoolMetaData metad, String
classname, Object[] params) {
this(metad);
this.oparams = params;
this.con = figureConstructor();
}

which then calls

public GenericPool(PoolMetaData metad) {
super(metad);
this.oparams = null;
this.con = null;
this.info = (GenericPoolMetaData) metad;
try {
init();
} catch (Exception e) {
log("GenericPool: Exception while initializing",
e);
}
}

which does an ObjectPool.init which will call
GenericPool.create

protected Object create() throws Exception {

String otype = info.getObjectType();

if (otype == null)
throw new ClassNotFoundException();

Class clazz = Class.forName(otype);
Object o = null;

if (this.con == null) {
o = clazz.newInstance();
return o;
} else {
o = this.con.newInstance(this.oparams);
}

return o;
}

As be be seen by this, the default constructor will be
null because this.con hasn't been yet initialized in
the

GenericPool(GenericPoolMetaData metad, String
classname, Object[] params)

call. But when that call completes, the this.con could
have a new values, which means that subsequent objects
could be initialized differently.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB