GroupAdapterAuthorizationSource { protected List<String> collectEntitiesFromAdapters(String username, Subject subject) { Set<String> userGroups = new HashSet<>(); groupsAdapters.forEach(adapter -> { final List<Group> groupRoles = adapter.getGroups(username, subject); if (groupRoles != null) { for (Group group : groupRoles) { if (roleRegexTemplate == null || roleRegexTemplate.isEmpty()) { userGroups.add(group.getName()); } else { userGroups.add(getSimpleName(group.getName())); } } } }); return new LinkedList<>(userGroups); } GroupAdapterAuthorizationSource();   }
@Test public void testConcurrency() throws Exception { final ExecutorService service = Executors.newFixedThreadPool(4); final CountDownLatch latch = new CountDownLatch(12); for (int i = 0; i < 12; i++) { service.submit(() -> { try { adapter.collectEntitiesFromAdapters(null, null); latch.countDown(); } catch (Exception ex){ ex.printStackTrace(); } }); } service.shutdown(); assertTrue(latch.await(3, TimeUnit.SECONDS)); }