SHARE
TWEET

Untitled

a guest Jul 12th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(String[] args)
  2. {
  3.     Set<Server> servers = getServers();
  4.     Map<String, String> serverData = new ConcurrentHashMap<>();
  5.  
  6.     for (Server server : servers)
  7.     {
  8.         String serverId = server.getIdentifier();
  9.         String data = server.fetchData();
  10.  
  11.         serverData.put(serverId, data);
  12.     }
  13. }
  14.      
  15. Set<Server> servers = getServers();
  16.     Map<String, String> serverData = new ConcurrentHashMap<>();
  17.  
  18.     servers.parallelStream().forEach((server) -> {
  19.         serverData.put(server.getIdentifier(), server.fetchData());
  20.     });
  21.      
  22. servers.parallelStream().forEach(server -> {
  23.     serverData.put(server.getIdentifier(), server.fetchData());
  24. });
  25.      
  26. final Set<Server> servers = getServers();
  27. Map<String, String> serverData = servers.parallelStream().collect(
  28.     toConcurrentMap(Server::getIdentifier, Server::fetchData));
  29.      
  30. import java.io.Console;
  31. import java.util.ArrayList;
  32.  
  33. ArrayList<String> list = new ArrayList<>();
  34. list.add("Item1");
  35. list.add("Item2");
  36. list.parallelStream().forEach((o) -> {
  37.     System.out.print(o);
  38. });
  39.      
  40. public staic void main(String[] args)
  41. {
  42.     Set<Server> servers = getServers();
  43.     Map<String, String> serverData = new ConcurrentHashMap<>();
  44.  
  45.     Parallel.ForEach(servers, new LoopBody<Server>()
  46.     {
  47.         public void run(Server server)
  48.         {
  49.              String serverId = server.getIdentifier();
  50.              String data = server.fetchData();
  51.  
  52.              serverData.put(serverId, data);
  53.         }
  54.     });
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top