简体   繁体   English

为什么 Thread.join() 方法使用“join”这个词?

[英]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.我开始研究以找出“join”一词用于Thread.join()方法的原因。 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(); Thread.pauseCaller();
  2. Thread.freezeCaller(); Thread.freezeCaller();
  3. Thread.focusThread(); Thread.focusThread();
  4. Thread.runBefore();线程.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. name 来自调用线程等待指定线程加入它的概念。

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.我完全无法理解上面这句话,也无法理解在这种方法中使用join一词的背景上下文。 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() .相反,它只是暂停调用线程以等待线程后跟join() So, can anyone tell the context of using the join word for this method?所以,任何人都可以告诉使用的情况下join了这个方法字?

“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. Join 是并发模型中使用的一个常用术语,这意味着两个独立运行的线程彼此同步,并且一个线程直到另一个线程到达特定的连接点才会继续运行。 So 2 threads are joining back together into one.所以2个线程重新连接在一起。 In Java, this is usually when the other Thread finishes its task.在 Java 中,这通常是在另一个线程完成其任务时。

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.请注意,在任务由可重用工作线程支持的模型中,这可能不完全相同,例如使用ExecutorService等待结果时,并使用CompletableFuture.join()阻塞直到结果可用。 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.该名称本身来自用于并行化任务并收集其结果的fork-join 模型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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