Grails:后台线程插件

发布于 2024-10-01 17:05:02 字数 43 浏览 0 评论 0原文

我有一个疑问,执行完成后是否需要删除后台线程?或者线程被自动清理并删除?

I have a doubt, Do I need to delete a background thread when the execute is done? Or the thread is automatically clean and deleted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

<逆流佳人身旁 2024-10-08 17:05:07

在 Java 和 Groovy 中,当不再引用对象实例时,它们会自动被垃圾回收。

一旦执行完毕,后台线程插件就不会保存对 Runnable 或传递给它的闭包(我们称它们为“线程”)的引用。

但是,您不应该在类级别的实例变量中保存对这些“线程”的大量引用。 (我想,无论如何,您都不会这样做。)请记住,Grails 中的服务是单例范围的,并且与 Grails 应用程序具有相同的生命周期。
相反,方法级别的对象实例在方法调用完成后被垃圾收集。

毕竟,根本不需要删除“线程”,只需不要将它们存储在实例变量中即可。

In Java and Groovy, object instances are automatically garbage-collected when there's no more reference to them.

The Background Thread Plugin doesn't hold references to Runnables or closures you pass to it (let's call them "threads") once those have been executed.

However, you shouldn't hold large arrays of references to these "threads" in instance variables at the class level. (I guess, you wouldn't do, anyway.) Remember that Services in Grails are singleton-scoped and have the same life span as the Grails application.
In contrast, object instances at the method level are garbage-collected after the method call has completed.

After all, there's simply no need to delete "threads", just don't store the them in instance variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文