简体   繁体   中英

Why is the word "join" is used for the Thread.join() method?

I started to do research to find out why the word "join" is used for the Thread.join() method. In fact, it waits for the thread to end on which it is called and pauses the main thread to wait for it so, there is nothing to join. So, its name should be something like:

  1. Thread.pauseCaller();
  2. Thread.freezeCaller();
  3. Thread.focusThread();
  4. Thread.runBefore();

I found one simple sentence after too much research which says that:

Thread.join(); name comes from the concept of the calling thread waiting until the specified thread joins it.

I am totally unable to get this above sentence into my mind and failed to understand the background context of using the word join for this method. What does the word "join" represent in this context? There is nothing to join anything else; instead, it just pauses the calling thread to wait for the thread followed by the join() . So, can anyone tell the context of using the join word for this method?

“join”一词来自Fork–Join 模型,其中“fork”表示将线程拆分为多个线程进行并行处理,“join”表示等待并行线程完成其部分,然后再继续单个线程线。

Join is a common term used in models of concurrency, which implies that two separate independently running threads are synchronising with each other and one thread will not proceed until the other reaches a specific join point. So 2 threads are joining back together into one. In Java, this is usually when the other Thread finishes its task.

Note that this might not be exactly the same in models where the tasks are backed by reusable worker threads, such as when using an ExecutorService to wait for a result, and using CompletableFuture.join() to block until the result is available. In this case the joining is more related to the task executed in parallel than the actual underlying worker thread which might be reused for other tasks afterwards.

The name itself comes from the fork-join model for parallelizing tasks and collecting their results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM