1

I have created a Custom processor which take care of saving some records in mysql database. For setting up mysql database i am using DBCPConnectionPool object in my custom processor which does work of saving data to database tables correctly, But i am worried of pooling mechanism i am not closing this connection after my logic of saving is completed. This is working for 2 to 3 flowfiles but when i send multiple flowfile will it work correctly?

DBCPService dbcpService = context.getProperty(DBCP_SERVICE).asControllerService(DBCPService.class);
Connection con = dbcpService.getConnection();

I am looking for clarification as my currently flow is working correctly with less number of flowfile

Varun Soni
  • 55
  • 6

1 Answers1

1

You should be returning it to the pool, most likely with a try-with-resource:

try (final Connection con = dbcpService.getConnection();
     final PreparedStatement st = con.prepareStatement(selectQuery)) {

}

You can always consult the standard processors to see what they do:

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java#L223

Bryan Bende
  • 18,320
  • 1
  • 28
  • 39
  • Thanks Bryan, for the advise of viewing the existing standard processors. this helped in clearing my doubts about it. – Varun Soni Jul 31 '19 at 15:03