2012-02-13 7 views
0

私がしたいことは、N個のデータベースをクエリし、その結果をJDBC経由で各データベースに固有のファイルに保存することです。私は並列でクエリを行うことを考えていたし、スレッドプールを介して考えていたが、スケーラブルですか?より良いアプローチ(俳優モデル)はありますか?JDBCクエリ複数のデータベース

ありがとうございました。

答えて

1

はい、スケーラブルです。常により良いアプローチがありますが、最も単純なものがあなたのニーズに合っていることを確認する必要があります。そうでない場合は、より良いアプローチを求める。

代替アプローチは、全く複雑である必要はありません。

// 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()); 
+0

私はExecutorServiceとExecutorCompletionServiceを使用して小さな概念実証を実装しましたが、正常に動作しているようです。あなたの見解では、他のアプローチは何ですか? – Radu

+0

このプロジェクトは、http://code.google.com/p/guzz/ – Radu

関連する問題