我在我的应用程序范围内放置了一个组件,以便在所有请求之间共享它,并且它包含一个 cfm 模板:
<cfcomponent output="false">
<cffunction name="run" output="false" returntype="void">
<cfset var tmp = false/>
<cftry>
<cfinclude template="inc.cfm"/>
<cfcatch>
<cffile action="append"
file="#ExpandPath("error.log")#"
output="ERROR: #cfcatch.message#"/>
</cfcatch>
</cftry>
</cffunction>
</cfcomponent>
包含的模板只是创建一个数组并检查数组长度是否应该是它应该是的,如果不是它写入
error.log
文件:<cfset tmp = [
"one",
"two",
"three"
]/>
<cfif ArrayLen(tmp) neq 3>
<cffile action="append"
file="#ExpandPath("error.log")#"
output="Length = #ArrayLen(tmp)#"/>
</cfif>
如果我然后在它上面运行负载(100 个并发线程),我的
error.log
中会出现以下项目文件...ERROR: element at position 3 of array variable "___IMPLICITARRYSTRUCTVAR0" cannot be found.
Length = 0
Length = 2
备注 我在 Java 1.7.0_09 之上使用 ColdFusion 9.0.1.274733。我已经在同一个 JRE 上测试了 Railo,它工作正常。
附加 下面也出现问题,改了
tmp
将变量添加到结构中并在 variables
中添加一个随机项任何地方都没有引用的范围......<cfcomponent output="false">
<!---
Some random variable that does nothing with the exception
of being the facilitator of my eternal pain
--->
<cfset variables.t = {}/>
<cffunction name="run" output="false" returntype="void">
<cfset var tmp = {}/>
<cftry>
<cfinclude template="inc2.cfm"/>
<cfcatch>
<cffile action="append"
file="#ExpandPath("error.log")#"
output="ERROR: #cfcatch.message#"/>
</cfcatch>
</cftry>
</cffunction>
</cfcomponent>
其中包括一个模板,与第一个非常相似,看起来像这样......
<cfset tmp.arr = [
"one",
"two",
"three"
]/>
<cfif ArrayLen(tmp.arr) neq 3>
<cffile action="append"
file="#ExpandPath("error.log")#"
output="Length = #ArrayLen(tmp.arr)#"/>
</cfif>
如果您删除
variables
中的项目范围它工作正常。如果您转储 #variables#
和 #local#
在模板中,一切都在您期望的位置。(从评论更新)
我已经将此问题作为 bug #3352462 提出来了。
最佳答案
这是基于彼得/您自己的上述评论。
数组和结构速记概念存在/存在许多错误,并且自 CF8 引入语法以来一直存在。 Adobe 修复它们的方法有点像打鼹鼠,而不是努力将问题一次性地、正确地解决掉。看起来你已经找到了另一个例子。不过,看看这是否仍然存在于 CF10 中会很有趣,因为我知道他们在开发周期中修复了更多问题。
解决它的唯一方法是在您看到这些问题的情况下不要使用该符号。
你能提出一个 bug对于这一点,Adobe 是否意识到了这一点?
还有一点值得注意,但与您在此处的具体问题无关:Java 1.7 尚不支持 CF。你可能想记住这一点。
关于coldfusion - 从 CFC 中包含 CFM 时的并发性和范围界定问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13053732/