Hi,
i have a question about pass connection in jpos project, here's my code for reference
public class HostServer implements ISORequestListener, Configurable{
long timeout;
private String queue;
private Space<String, Context> sp;
public static void main(String[] args){
Q2 q2 = new Q2();
q2.start();
}
@SuppressWarnings("unchecked")
@Override
public void setConfiguration(Configuration cfg) throws ConfigurationException {
timeout = cfg.getLong ("timeout");
sp = (Space<String,Context>) SpaceFactory.getSpace (cfg.get ("space"));
queue = cfg.get ("queue");
if (queue == null){
throw new ConfigurationException ("queue property not specified");
}
}
@Override
public boolean process(ISOSource isoSrc, ISOMsg isoMsg) {
try {
Logger msgLog = LogManager.getLogger(HostServer.class);
UUID hashUniqId =UUID.randomUUID();
DBConnectionPool conn = (DBConnectionPool) NameRegistrar.getIfExists("connection.pool.dbpool");
Connection cn = conn.getConnection();
Context ctx = new Context ();
ctx.put (Constant.ISOSOURCE, isoSrc);
ctx.put (Constant.REQUEST, isoMsg);
ctx.put (Constant.UUID, hashUniqId);
ctx.put (Constant.Connection, cn);
sp.out(queue, ctx, timeout);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
it works well, but have you recommend it?maybe it can potentially cause a connection leak or decrease the performance.
FYI, every time i end a request, i close the connection
source.send(resMsg);
GlobalFunction.closeConnection(st, rs, con);
need some expert advice :)
Thanks.