I have heard Java 8 provides a lot of utilities regarding concurrent computing. Therefore I am wondering what is the simplest way to parallelise the given for loop?
using my Parallel.For, your code might look like the following,
public staic void main(String[] args)
{
Set servers = getServers();
Map serverData = new ConcurrentHashMap<>();
Parallel.ForEach(servers, new LoopBody()
{
public void run(Server server)
{
String serverId = server.getIdentifier();
String data = server.fetchData();
serverData.put(serverId, data);
}
});
}