Source:
<code>public QueryControlResult createQueryWithCheckpoint(final AvroDag avroDag, final QueryCheckpoint checkpointedState) { final QueryControlResult queryControlResult = new QueryControlResult(); final String queryId = avroDag.getQueryId(); queryControlResult.setQueryId(queryId); try { checkpointManager.storeQuery(avroDag); final String appId = avroDag.getAppId(); if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Create Query [aid: {0}, qid: {2}]", new Object[]{appId, queryId}); } if (!applicationMap.containsKey(appId)) { createApplication(appId, avroDag.getJarPaths()); } final ApplicationInfo applicationInfo = applicationMap.get(appId); if (applicationInfo.getGroups().size() == 0) { <START> createGroup(applicationInfo); <END> } final DAG<ConfigVertex, MISTEdge> configDag; if (checkpointedState == null) { configDag = configDagGenerator.generate(avroDag); } else { configDag = configDagGenerator.generateWithCheckpointedStates(avroDag, checkpointedState); } while (applicationInfo.getGroups().isEmpty()) { Thread.sleep(100); } final Query query = createAndStartQuery(queryId, applicationInfo, configDag); queryControlResult.setIsSuccess(true); queryControlResult.setMsg(ResultMessage.submitSuccess(queryId)); return queryControlResult; } catch (final Exception e) { e.printStackTrace(); LOG.log(Level.SEVERE, "An exception occurred while starting {0} query: {1}", new Object[] {queryId, e.toString()}); queryControlResult.setIsSuccess(false); queryControlResult.setMsg(e.getMessage()); return queryControlResult; } }</code><technical_language>Multiple groups created time threads execute this code</technical_language>

Target:
public QueryControlResult createQueryWithCheckpoint(final AvroDag avroDag, final QueryCheckpoint checkpointedState) { final QueryControlResult queryControlResult = new QueryControlResult(); final String queryId = avroDag.getQueryId(); queryControlResult.setQueryId(queryId); try { checkpointManager.storeQuery(avroDag); final String appId = avroDag.getAppId(); if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Create Query [aid: {0}, qid: {2}]", new Object[]{appId, queryId}); } if (!applicationMap.containsKey(appId)) { createApplication(appId, avroDag.getJarPaths()); } final ApplicationInfo applicationInfo = applicationMap.get(appId); if (applicationInfo.getGroups().size() == 0) { synchronized (applicationInfo) { if (applicationInfo.getGroups().size() == 0) { createGroup(applicationInfo); while (applicationInfo.getGroups().isEmpty()) { Thread.sleep(100); } } } } final DAG<ConfigVertex, MISTEdge> configDag; if (checkpointedState == null) { configDag = configDagGenerator.generate(avroDag); } else { configDag = configDagGenerator.generateWithCheckpointedStates(avroDag, checkpointedState); } final Query query = createAndStartQuery(queryId, applicationInfo, configDag); queryControlResult.setIsSuccess(true); queryControlResult.setMsg(ResultMessage.submitSuccess(queryId)); return queryControlResult; } catch (final Exception e) { e.printStackTrace(); LOG.log(Level.SEVERE, "An exception occurred while starting {0} query: {1}", new Object[] {queryId, e.toString()}); queryControlResult.setIsSuccess(false); queryControlResult.setMsg(e.getMessage()); return queryControlResult; } }