0

I have a code where it connects to 3 databases, and runs one query on each database. This is done sequentially.

1) First I have put 3 Queries in a property file.

2) I iterate the Property file and store the Queries in one Array List.

while((propData=reader.readLine())!=null)
{
  /* ....... Iterates the prop file ...... */
}

I have stored the query which I got from Property file in one Array List.

ArrayList<String> list = new ArrayList<String>();

Then I iterated over the list, get each Query , Run it and store the results.

for(int i=0;i<list.size();i++){

String ProcessedRecord = list.get(i);
String app_name = application.get(i);

ResultSet feedDetails = runQuery(ProcessedRecord,app_name); 

while(feedDetails.next()) 
{
  /* ...... */
}

} // End of For Loop

But I want to do this Parallely. Meaning I want to connect to all three different databases parallelly, run the Queries individually on respective database, and bring in the Result Set.

Please help me with the code , how to do it ?

Thanks,

user3254725
  • 65
  • 1
  • 9
  • *"But I want to do this sequentially. Meaning I want to connect to all three different databases parallelly"* --- thats a contradiction. What is it? Parallel or in sequence? Also : What is *"a code"* supposed to be? Are we talking ciphercodes? – specializt Jun 14 '16 at 12:15
  • if you want to run parallel you have to spawn different threads,depending on the framework you are using it could be very simple or very hard. – Francesco Pirrone Jun 14 '16 at 12:18
  • How familiar are you with concurrency? And which Java version is in use? https://docs.oracle.com/javase/tutorial/collections/streams/parallelism.html – Fildor Jun 14 '16 at 12:21
  • Im just a beginner in Concurrency . I am using Java version 7. – user3254725 Jun 14 '16 at 12:31
  • In favor of parallel stream, you could use Fork/Join API or a good old ExecutorService. In case of Java7, parallel streams are not available. – Fildor Jun 14 '16 at 12:31
  • @ specializt Sorry for the Typo . I want the code to do the task Parallely. I have edited the Question – user3254725 Jun 14 '16 at 12:32
  • I think it can be done through Concurrency API . But I am not sure how to implement it in my code . It would be good if someone could help me out with a sample code – user3254725 Jun 14 '16 at 12:34
  • https://docs.oracle.com/javase/tutorial/essential/concurrency/executors.html That would probably be a good strating point for you. – Fildor Jun 14 '16 at 12:35
  • Creating threads. http://stackoverflow.com/questions/2865315/threads-in-java – gradski Jun 14 '16 at 12:47

0 Answers0