循环中的coldfusion线程失去作用域

循环中的coldfusion线程失去作用域,coldfusion,thread-safety,coldfusion-9,cfthread,Coldfusion,Thread Safety,Coldfusion 9,Cfthread,我目前正在努力掌握线程。我觉得这可能与我的望远镜有关;然而,我看不出我在这方面出了什么问题 我的CFC包含以下功能: <cfcomponent output="false" hint="thread stuff."> <cffunction name="threadTest" access="public" returntype="struct"> <cfscript> local.lstOne = "1,

我目前正在努力掌握线程。我觉得这可能与我的望远镜有关;然而,我看不出我在这方面出了什么问题

我的CFC包含以下功能:

<cfcomponent output="false" hint="thread stuff.">
    <cffunction name="threadTest" access="public" returntype="struct">
    <cfscript>
        local.lstOne            = "1,2,3,4,5,6";
        local.a                 = [];
        local.s                 = {};
        local.lst               = "";

        for(local.x = 1; local.x lte listlen(local.lstOne,','); local.x++){
            local.lst           &= (len(local.lst) gt 0) ? ',thr#local.x#' : 'thr#local.x#';

            thread action="run" name="thr#local.x#" nIndex="#local.x#" aArray="#local.a#"{

                thread.y        = attributes.nIndex;
                thread.aArray   = attributes.aArray;
                if(thread.y mod 2){
                    thread.c    = 1;
                } else {
                    thread.c    = 0;
                }

                thread.stArgs       = {};
                thread.stArgs.nMod  = thread.c;

                arrayAppend(thread.aArray, thread.stArgs);
            }
        }

        threadJoin(local.lst);

        local.s.counts          = local.a;

        return local.s;
    </cfscript>
</cffunction>
</cfcomponent>

local.lstOne=“1,2,3,4,5,6”;
local.a=[];
local.s={};
local.lst=“”;
对于(local.x=1;local.x lte listlen(local.lstOne,“,”);local.x++){
local.lst&=(len(local.lst)gt 0),thr#local.x#':'thr#local.x#';
thread action=“run”name=“thr#local.x#”nIndex=“#local.x#”aArray=“#local.a#”{
thread.y=attributes.nIndex;
thread.aArray=attributes.aArray;
如果(螺纹y模块2){
螺纹c=1;
}否则{
螺纹c=0;
}
thread.stArgs={};
thread.stArgs.nMod=thread.c;
arrayAppend(thread.aArray,thread.stArgs);
}
}
螺纹连接(本地.lst);
局部s.计数=局部a;
返回本地.s;
我有一个CFM页面,看起来有点像这样:

<cfscript>
theThread = createObject( "component", "ThreadStuff" ).init();
theThread.threadTest();
</cfscript>

theThread=createObject(“组件”、“线程”).init();
thread.threadTest();
当我运行此命令时,coldfusion返回错误元素X在本地未定义。

我不明白为什么在循环的第一次迭代后它会丢失local.x(我已经通过在循环开始和结束时进行转储来证明了这一点,但它无法到达local.x=2)


哪里可能出错?

如果问题是变量local.x没有递增,那么从注释掉所有线程内容开始。将其替换为本地的writedump。在循环之前和之后写入本地范围

一旦获得local.x增量,就添加空线程。继续编写本地作用域,以便查看这是否是导致问题的原因。如果local.x仍在递增,请添加非常小的代码位,直到找到导致问题的位。

Coldfusion 9.0.0(本问题中使用的版本:9,0,0251028)存在一个错误,当在函数的循环中使用线程时,局部作用域会中断


此问题在Coldfusion 9.0.1中已修复,请参见此处的详细信息:id:80153。

我在CF 9(9,0,2282541)上运行此操作时没有出错。它返回了带有空
a
array的
counts
struct。。。但这可能更多的是我的代码错了,我的主要问题是本地.x不存在。。。不确定如何调试该问题。这是正确的代码吗?它最初对我来说失败了,因为CFC中没有
init()
函数。如果这是一个节略版本,请用准确的代码编辑,希望我能重新纠正你的错误。这不是准确的代码。。。init没有任何可能影响此的内容。。。application.cfc可能很难识别,也不确定如何告诉您
local.x
变量未定义,但这段代码无法实现您的期望。
local.s
结构只包含一个项,它是一个空数组
local.a
。当前,
local.a
作为空线程传入,然后它不会在线程内修改。所以它还是空的。要让结构从线程返回计数,您需要将该结构传递到线程中,并在线程块中将数组附加到该结构中。因此,只要我添加了一个在local.x中没有任何内容的线程标记,就会中断。