I’m trying to use threads or Executor Service in my Jenkins shared library. While executing, it doesn’t throw any errors, but it doesn’t seem like any operations are performed by the threads.
void checkMetaFilters(String datacenter, LinkedList<String> clientIDs, HashMap filters) {
if (!filters) {
return
}
ConcurrentHashMap<String, HashMap> nodesData = new ConcurrentHashMap<String, HashMap>()
ExecutorService executorService = Executors.newFixedThreadPool(NOMAD_MAX_THREADS)
for (int i = 0; i < clientIDs.size(); i++) {
final String id = clientIDs.get(i)
Logger.info(id)
executorService.submit ({ ->
Logger.debug(id)
HashMap nodeData = getNomadNodeData(datacenter, id)
Logger.debug(nodeData)
if (isMetaFilterMatching(nodeData, filters)) {
nodesData.put(id, nodeData)
}
})
}
Logger.debug("Shutting down threads...")
sleep(5000)
executorService.shutdown()
try {
Logger.debug("Awaiting termination...")
executorService.awaitTermination(20, TimeUnit.SECONDS)
}
catch (InterruptedException e) {
Logger.printStackTrace(e)
}
Logger.debug(nodesData)
clientIDs.clear()
clientIDs.addAll(nodesData.keySet())
}
I’m not sure if I’m missing something or if threads simply doesn’t work.
Thanks in advance
New contributor
Yogeshwaran Rajendran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.