private static void process(DBManager dbManager, String region, String ip) throws Exception { System.out.println("Reading all users from region : " + region + ". Forward to " + ip); ConcurrentMap<UserKey, User> users = dbManager.userDBDao.getAllUsers(region); System.out.println("Read " + users.size() + " users."); int count = 0; List<ForwardingTokenEntry> entryList = new ArrayList<>(1100); for (User user : users.values()) { for (DashBoard dashBoard : user.profile.dashBoards) { for (Device device : dashBoard.devices) { if (device != null && device.token != null) { count++; entryList.add(new ForwardingTokenEntry(device.token, ip, user.email, dashBoard.id, device.id)); } } } if (entryList.size() > 1000) { dbManager.forwardingTokenDBDao.insertTokenHostBatch(entryList); System.out.println(entryList.size() + " tokens inserted."); entryList = new ArrayList<>(1100); } } if (entryList.size() > 0) { dbManager.forwardingTokenDBDao.insertTokenHostBatch(entryList); System.out.println(entryList.size() + " tokens inserted."); } System.out.println("Total entries : " + count); }