It is necessary to return json in which there are links 5000+ files. I create a model
ModelAndView modelAndView = new JsonHelper().createModelAndJson(url); return modelAndView; The JsonHelper class JsonHelper a stream that contains the List of files and populates the model with files.
public ModelAndView createModelAndJson(String url) { JsonThread jsonThread = new JsonThread(url); Thread mainThread = new Thread(jsonThread); mainThread.start(); try { mainThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } return jsonThread.getModelAndView(); } File search also goes further in the streams. As a result, it shows everything correctly, but there is no simultaneous execution of the first thread, all other threads work in parallel and show the result immediately. Ie the first created query works separately from the rest and their launch slows down.