- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个调用 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/
我有一个调用 cfcomponent 对象的循环。
使用 Railo,我正在使用 cfthread 处理大型视频文件。文件上传后,我调用 使用 ffmpeg 处理文件(type="task"是 Railo 特定的)。对于大文件,这可能需要一段时间,看起
我有一个交易虚拟物品的应用程序,并且有一个页面可以获取我的所有帐户,并且为每个帐户创建一个线程,该线程首先登录该帐户,然后在 session 处于 Activity 状态时搜索并购买物品。在这一点上,
现在我将它用于 csv 文件的后端处理,并且 cf8 标准仅限于十个线程,我想确保我不会以某种方式使服务器过载...... 有什么建议? 我正在制作唯一命名的线程,但我担心性能...如果我需要停止线程
我们有几千个目录,其中的页面每天访问量高达 50 万次。在每个页面点击结束时,我们将一些 CGI 变量插入到数据库中。如果提交了表单或执行了搜索,我们会将其中的一些信息插入到另一个数据库中。不需要从这
我正在尝试改进我的一份报告的执行时间,该报告使用 cfcharts 打印图表。代码本身是一个实体循环,我为每个实体创建了一个图表(这是一个比较报告)。 由于报告的复杂性,通过内联执行此操作需要将近一分
我在 ColdFusion 应用程序中使用 CFTHREAD。根据我从 Ben Nadel ( https://www.bennadel.com/blog/2980-terminating-async
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我以前没有使用过 cfthread,但我使用以下代码,但它不起作用。
我以前没有使用过 cfthread,但我使用以下代码,但它不起作用。
感谢回复!!但我仍然无法做到。我得到的错误是 “元素 objGet1 在类型为 Coldfusion.runtime.VariableScope 的 Java 对象中未定义。” 下面是我的完整代码。我
我是一名优秀的程序员,十分优秀!