gpt4 book ai didi

multithreading - CFTHREAD 执行两次

转载 作者:行者123 更新时间:2023-12-04 06:41:27 25 4
gpt4 key购买 nike

我有一个调用 cfcomponent 对象的循环。

    <cfset queue_list = "1,2,3">        
<cfloop list="#queue_list#" index="z">
<cfset args = StructNew()>
<cfset args.group_num = z>
<cfset args.client_id = 1>
<cfset processdownloads = downloader.ProcessDownload(argumentCollection=args)>
</cfloop>

该组件具有以下功能:

    <cffunction name="ProcessDownload" access="public" output="false">
<cfargument name="group_num" type="numeric" required="yes">
<cfargument name="client_id" type="numeric" required="yes">

<cfset variables = arguments>

<cfthread action="RUN" name="download_#variables.client_id#_#variables.group_num#" priority="high">

<cffile action="WRITE" file="#expandpath('download\download_in_process\')##variables.group_num#.json" output="#variables.group_num#">

</cfthread>

</cffunction>

当我运行它时,我收到以下错误:

cfthread 标记的属性验证错误。无法创建名为 DOWNLOAD_4003_3 的线程。线程名称在一个页面中必须是唯一的。
错误发生在第29行。

我不知道为什么,但它似乎运行了两次。它不应该生成一个具有唯一线程名称的新线程,从而避免线程名称冲突吗?

最佳答案

将 group_num 作为属性传入,这样您就可以在内部访问它,而不会出现变量范围被覆盖的问题。

<cfthread action="RUN" name="download_#arguments.client_id#_#arguments.group_num#" priority="high" group_num="#arguments.group_num#">
<cffile action="WRITE" file="#expandpath('download\download_in_process\')##attributes.group_num#.json" output="#attributes.group_num#">
</cfthread>

其他人都是对的,问题在于您的变量范围。发生的事情是每个循环都覆盖变量范围,所以当线程被创建时,它从变量范围获取线程名称,它已经设置为 3 ...所以所有三个线程可能会尝试设置为相同的姓名。

你能用参数给它命名吗?如果没有......你可以使用本地。获取名称并将信息传递到 CFThread Creation。

关于组件内部,您是正确的,您不能访问参数等,这与组件外部的行为非常不同。

Ben Nadel 就这些问题写了一篇不错的文章 http://www.bennadel.com/blog/2215-an-experiment-in-passing-variables-into-a-cfthread-tag-by-reference.htm

Ben 像往常一样获胜。

关于multithreading - CFTHREAD 执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28706694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com