shivang sarawagi wrote:Or is there a way to iterate through a set of users, split the task into several threads using executor framework/Batch process or something?
Sure, that sounds like a good idea. But really if you're going to have a system of that size then you aren't going to be running it on a single machine anyway, so there may be better ways. One important thing you should do is to reduce that 30 seconds to something more practical.
Depends what format you keep the followers in. If you can get them into a List, you can use a Stream for sequential access.
followersList.stream().map(f -> f.getAddress()).forEach(a -> sendMessage(a));
It is easy enough to change a Stream from sequential to parallel, by calling its parallel() method.
If you are using a single thread, you can use the List's forEach method directly.
This sort of code will only work in Java8. You can get Streams from all sorts of other things, e.g.a BufferedReader, or a file Path. Don't know whether you can get a Stream from an SQL connection.