How to know if other threads have finished?

前端 未结 12 1651
野性不改
野性不改 2020-11-22 14:05

I have an object with a method named StartDownload(), that starts three threads.

How do I get a notification when each thread has finished executing?

12条回答
  •  有刺的猬
    2020-11-22 14:39

    Look at the Java documentation for the Thread class. You can check the thread's state. If you put the three threads in member variables, then all three threads can read each other's states.

    You have to be a bit careful, though, because you can cause race conditions between the threads. Just try to avoid complicated logic based on the state of the other threads. Definitely avoid multiple threads writing to the same variables.

提交回复
热议问题