coldfusion (railo) and cfthread not working as I would expect

我与影子孤独终老i 提交于 2019-12-11 01:03:25

问题


I've not used cfthread before but i'm using the following code and it's not working.

<cfloop from="1" to="5" index="local.pageNo">

            <cfthread name="thr#local.pageNo#" threadIndex="#local.pageNo#" action="run">

                <cfif local.pageNo GT 1>
                    <cfhttp url="#local.apiURL#&page=#local.pageNo#" method="get" result="local.myResults" >
                    </cfhttp>
                    <cfset local.myResponse = deserializejson(local.myResults.filecontent)>
                </cfif>

                <cfloop from="1" to="#arrayLen(local.myResponse.result)#" index="i">
                    <cfset local.apartmentList = listAppend(local.apartmentList,local.myResponse.result[i].id & '-0')>
                </cfloop>

            </cfthread>

        </cfloop>

        <cfthread action="join" name="thr1,thr2,thr3,thr4,thr5"/>

I'm expecting local.apartmentList to be a big list of ID's but it returns empty. It's almost as if the code inside the thread is just being skipped. Can anybody spot what i'm doing wrong?


回答1:


When you're using <cfthread>, the code within those tags is not run within the same context as the code around it. So you need to pass any variables you intend to use into it (as attributes of the <cfthread> tag), or "share" them via the request scope.

So your <cfthread> block won't know what variables like local.pageNo are.

Any error occurring in <cfthread> processing is logged, so you need to look at your logs to see what errors are cropping up.



来源:https://stackoverflow.com/questions/24821580/coldfusion-railo-and-cfthread-not-working-as-i-would-expect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!