Here is a sample solution my fork on SteamEx
StreamEx.of(idsList).parallel()
.splitToList(100)
.flatCollection(ids -> dao.list(ids)) // assume dao.list(...) returns a list of records, you can switch to flatArray/flatMap per the return type of dao.list
.toList();
Update:
I did some performance test for the comments under the OP: (unit is milliseconds)
size the of the id list: 100, 1000, 10_000
All in one query: 3.5, 6.9, 282.2
By batch(200) 3.5, 4.8, 186.0
One by One: 7.8, 35.5, 572.9
Based on the performance test result on MySQL 5.7 and my personal experiences, I would say:
1, if there are only couple of ids, maybe it's ok to query one by one.
2, if there are hundreds/thousands or even more, batch or all in one query is necessary.
3, if you want to execute the query with all ids in one statement, please be aware:
a) The limitation is 1000 for Oracle, 8623 for SQL server
b) In the limitation doesn't mean the database is tuned for the maximum capability.
c) it may take long to execute big query and the database could be choked by long query
d), timeout or over the packet size.