简体   繁体   中英

Connect multiple MySQL server using JDBC Java

I have 10 different MySQL servers with the same schema design. Now I have to query each server and merge results in java which is same as UNION ALL in SQL.

All DB servers return the same data format, and I tried sequential call of all server but it takes more time.

How can I speed up the process?

Scenario

在此处输入图片说明

This probably your sequential logic:

  1. List<YourObject> arr = new ArrayList<YourObject>();
  2. X = 1.
  3. Select * from X.
  4. add results to arr.
  5. X++ until no more databases.

I can think of a solution that might consume less time:

How about this logic:

you can cut the sequential into threads. each thread will connect to a different server. once you have result from a server lock the arr and add the results.

  1. Create a Connection thread to each Server.
  2. Run Threads to connect and wait for result.
  3. Each incoming result add to a merged array. (don't forget to lock global result array).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM