0

What I want to do is query N databases and store the results in a file specific to each database via JDBC. I was thinking of doing the queries in parallel and was thinking via thread pool, but is that scalable? Is there a better approach(actor-model)?

Thanks.

0

1 Answer 1

1

Yes, it is scalable. There are always better approaches, but you need to be sure that the simplest one suits your needs. If it doesn't then seek for better approaches.

An alternative approach doesn't have to be complicated at all.

// initialize an executor service
ExecutorService executor = Executors.newCachedThreadPool();

// externalize the access to every database in a method declared in a class
// that implements Runnable
class Oracle implements Runnable {
  @Override
  public void run() {
    // load the driver
    // prepare the statement
    // get the connection
    // execute the statement and get the results
    // save the results to a file
  }
}

// execute every db access withing the executor
executor.execute(new Oracle());
executor.execute(new SqlServer());
executor.execute(new MySql());
Sign up to request clarification or add additional context in comments.

2 Comments

I've implemented a small proof of concept using ExecutorService and ExecutorCompletionService and it seems to be working ok. In your perspective, what are other approaches?
Found this project that is quite interesting at a first look code.google.com/p/guzz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.