Sean
Sean

Reputation: 1474

Quarkus read `ResultSet` and process with multi-threads

I'm trying to read a JDBC ResultSet in parallel and do some processing on each record in a Quarkus service. There could be lots of records in the ResultSet so I don't want to read all the data upfront. I'd rather stream the results to a processor.

I have wrapped the ResultSet object so I can read from it in a thread safe manner. However I am struggling to find a way to read the results in multiple threads. I've tried an ExecutorService but the DB context gets lost and the ResultSet is closed in the thread.

I considered using a SmallRye Multi object to do the processing, but I struggled to find a way to add the records to the item list and I'm not sure that will create multiple threads anyway.

Is there a preferred multi-threading library for Quarkus?

Upvotes: 1

Views: 498

Answers (1)

Ivan
Ivan

Reputation: 8758

You can use producer-consumer pattern: one thread opens database connection, reads data from ResultSet and places it into Blocking Queue with some limited size and several other threads get data from that blocking queue and process it

Upvotes: 2

Related Questions