Balaji
Balaji

Reputation: 869

Java Concurrency on JDBC result

I would like to apply Java Concurrent i.e. Callable for resultset. The scenario is -

  1. Query the DB using JDBC.
  2. Send the resultset to callable to write to different files.

Since the data would be large i would like to resultset. Please help me to get better approach for the problem.

Upvotes: 1

Views: 258

Answers (2)

Daniel De León
Daniel De León

Reputation: 13649

I suppose you are programming under swing or javaFX, then you are blocking the GUI thread.

So you must create another Thread to process the jdbc request, and display a 'please wait' message.

Do something like this:

new Thread(new Runnable(){
  void run(){
   final result = jdbc.getResultSet();
   // Under JavaFX 2
   Platform.runLater( new Runnable() {
          public void run() {
                 //Show results
          }
   } );
   // Under Swing
   SwingUtilities.invokeLater(new Runnable() {
          public void run() {
                 //Show results
          }
   });
  }
}
);

Upvotes: 0

Adam Dyga
Adam Dyga

Reputation: 8896

Because of the way ResultSet is designed it is not supposed to be used concurrently by many threads. But you can create one thread that iterates over the result set and send row data to Callables that will perform further processing of each row (or group of rows).

Upvotes: 2

Related Questions