【问题标题】:node.js list all active threadsnode.js 列出所有活动线程
【发布时间】:2020-05-09 06:48:51
【问题描述】:

我现在正在尝试自学如何使用 node.js 进行同步和异步编写。 只是出于兴趣,我想在尝试使用 fs.writeFile() 将随机行写入 txt.-file 时检查所有活动线程。如果有任何方法可以做到这一点,我会很高兴得到一个可以帮助我理解这个主题的答案。

【问题讨论】:

  • 欢迎来到 SO。请添加您迄今为止尝试过的代码,以便我们可以帮助解决问题。这个问题似乎很广泛

标签: javascript node.js asynchronous fs asynchronous-javascript


【解决方案1】:

相比使用多线程,在 Node.js 中使用多进程要容易得多。比如cluster模块可以在多个进程中运行相同的js代码。

有关集群模块的更多信息:How to use clusters in node js?

要获取所有进程的列表,请参阅这篇文章:how to get the list of process

有关 node.js 中线程的更多信息,请参阅:https://nodejs.org/api/worker_threads.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 2015-10-10
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多