0

I am using jpos 2.1.0 where i am using external packager xml file for iso8583 client. Due to large number of request in two or three days, i encountered "Too Many Files Open" and i have set ulimit -n = 50000. I doubt that the packager files are not been closed properly due to which this limit has been exceeded. Please help me to close the open file properly.

    JposLogger logger = new JposLogger(isoLogLocation);
    org.jpos.iso.ISOPackager customPackager = new GenericPackager(isoPackagerLocation+iso8583Properties.getPackager());
    BaseChannel channel = new ASCIIChannel(iso8583Properties.getServerIp(), Integer.parseInt(iso8583Properties.getServerPort()), customPackager);
    logger.jposlogconfig(channel);

    try {
        channel.setTimeout(45000);
        channel.connect();
    }catch(Exception ex) {
        log4j.error(ex.getMessage());
        throw new ConnectIpsException("Unable to establish connection with bank.");
    }

    log4j.info("Connection established using ASCIIChannel");

    ISOMsg m = new ISOMsg();
    m.set(0, "1200");
            ........
    m.set(126, "connectIPS");

    m.setPackager(customPackager);
    log4j.info(ISOUtil.hexdump(m.pack()));
    channel.send(m);
    log4j.info("Message has been send");

    ISOMsg r = channel.receive();
    r.setPackager(customPackager);
    log4j.info(ISOUtil.hexdump(r.pack()));
    String actionCode = (String) r.getValue("39");

    channel.disconnect();
    return bancsxfr;
}

1 Answers1

0

You know when you open a file, a socket, or a channel, you need to close it, right?

I don't see a finally in your try that would close the channel.

You have a huge leak there.

apr
  • 1,288
  • 7
  • 8
  • I understand that i need to close all the open channel, files. However i cannot find the closure methods for this case. Both org.jpos.iso.ISOPackager and BaseChannel does't provide close() method to explicitly close the Channel as well as Packager file. I'll be thankful if you can send me some example code. – Diwas Sapkota Apr 28 '19 at 04:11
  • channel.disconnect() will do the job. – apr Apr 29 '19 at 19:04
  • I was using channel.disconnect(), however it was not in finally block. But i tried keeping at finally block, still getting the same issue. – Diwas Sapkota May 08 '19 at 10:32