I need to start an additional stream in the main procedure, which will read the information for some of its value, and stop the main parent stream.

How can I get the main thread?

  • 2
    What does it mean to suspend? - cy6erGn0m
  • @ cy6erGn0m: in the worst case, suspend . - VladD
  • Suspend the main thread? - KoVadim

2 answers 2

  1. Pass the necessary parameters to the thread-procedure, here's a link to the documentation with examples.
  2. For synchronization, use non-manual flow control (God forbid), but, for example, CyclicBarrier .

    To stop the main thread and wait for the completion of the additional stream, add join() after the start:

     Thread thread = new Thread() { @Override public void run() { //код дополнительного потока } }; thread.start(); thread.join(); 

    To control the main stream from the additional stream is in most cases not a very good solution. Try to organize the logic in such a way that such a need does not arise.