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.

    1 answer 1

    The join method blocks the execution of the current thread until mainThread completes. So your code execution is consistent.

    • In general, the joint was inside mainTread. Tried to just sleep flow, and they all fall asleep equally and do not slow down their first flow. Eventually. I did it not flow. And just an object with a method that performs the same thing. Ie, if earlier a stream was created for each request from the user, which further multiplies the threads. I create an object that also produces threads - Kleimosc