不调用Thread#join可以吗?
不调用Thread#join
可以吗?在这种情况下,我不在乎线程是否崩溃 - 我只希望 Unicorn 继续处理。
class MyMiddleware
def initialize(app)
@app = app
end
def call(env)
t = Thread.new { sleep 1 }
t.join # is it ok if I skip this?
@app.call env
end
end
我会得到“僵尸线程”或类似的东西吗?
Is it OK not to call Thread#join
? In this case, I don't care if the thread blows up - I just want Unicorn to keep processing.
class MyMiddleware
def initialize(app)
@app = app
end
def call(env)
t = Thread.new { sleep 1 }
t.join # is it ok if I skip this?
@app.call env
end
end
Will I get "zombie threads" or something like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不调用
join
是完全可以的 - 事实上,多线程代码通常根本不需要join
。仅当您需要阻塞直到新线程完成时,才应调用join
。你不会得到“僵尸”线程。新线程将运行直到完成,然后为您清理自身。
It's perfectly fine to not call
join
- in fact,join
is often not needed at all with multithreaded code. You should only calljoin
if you need to block until the new thread completes.You won't get a "zombie" thread. The new thread will run until completion, then clean itself up for you.