Coldfusion(railo)和cfthread无法正常工作 [英] coldfusion (railo) and cfthread not working as I would expect

查看:97
本文介绍了Coldfusion(railo)和cfthread无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前没有使用过cfthread,但是我正在使用以下代码,但它不起作用。

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"/>

我期望local.apartmentList是ID的大列表,但返回的是空值。这几乎就像只是在跳过线程内的代码。有人可以发现我在做什么错吗?

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?

推荐答案

使用< cfthread> ,这些标记中的代码与周围的代码不在同一上下文中运行。因此,您需要将要使用的任何变量(作为< cfthread> 标记的属性)传递给它,或通过请求范围共享它们。

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.

所以您的< cfthread> 块将不知道什么变量,例如 local.pageNo

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

记录在< cfthread> 处理中发生的任何错误,因此您需要查看您的日志以查看出现了哪些错误。

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

这篇关于Coldfusion(railo)和cfthread无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆