开发者

Kill a running process in ColdFusion?

I'm writing a database load script in ColdFusion. It loads about 150,000 records across a dozen tables. I am running the script through a web browser request. Is there any way to kill the process once I've requested the page? I can stop the page in the browser, but the database inserts continue on the backend until the script has completed, which makes the debugging process very slow since I have to run the entire script each time. Is there anything I can do through the Java backend?

The environment I'm in is ColdFusion 8 running through IIS. I have the performance monitoring disabled, but I'd like to be abl开发者_JS百科e to mimic the ability to kill jobs as in the performance monitor.


I'd tried to make something like Unix pid-file: your script should periodically (maybe each 10/100/1000 iterations) check the availability of some file in the filesystem and stop executing if it contains certain value, or maybe if exists or not at all.

Of course, this can be a field in the database, variable in application scope (with appropriate locking strategy), or anything you find suitable.

You also need second script which will be changing the state of your "pid-object". This can be as simple as another .cfm you can pull with the browser.


In the loop through the 150,000 records can you just stop it at whatever number you think is appropriate. Set a counter variable and whenever it gets there in the loop just <cfabort> or <cfbreak> .


You will probably want to run the process using cfthread.

Start your process like...

<cfthread name="myThread" action="run"> 
    ...Your loop to insert into database....
</cfthread>

Then you can kill the thread by using...

<cfthread action="terminate" name="myThread"/>


If you have management software such as FusionReactor installed, you can use that to halt running scripts.


with some products like fusionreactor, you can kill the underlying java thread, but if the database actually has control of the request, you can't make it stop (on the database). You have to wait until the database returns control of the thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜