I've been working on a project recently that is an ideal use of ColdFusion's threading functionality. The application needs to send a large number of web service requests, and then combine the results.
When you start using threads, the first thing you notice is that the maximum number of threads you can have running at once is controlled by a setting the CF admin. As you'd expect, once the threashold has been reached, further threads are queued, and started as running threads complete. All seems quite reasonable...
...but what you probably wouldn't expect, and what I certainly didn't was that its quite possible that these queued threads will never be run! Sure, when a thread's code finishes, or you terminate a thread then as you'd expect, a queued thread takes it place. However, if you threas dies with a CF error whuch has not been trapped and handled, then it seems, as far as CFs thread manager is concerned, it is finished, so, no queued thread is started!
In my case, I had a small fault in my thread code. Since my threads were being fired off dozens at a time, very quickly, I found that I had hundred of queued threads which were never being run.
Moral of the story: Make SURE you put full error handling into your thread code. Its probably also a good idea to add in some error logging as well, otherwise it can be very hard to even find out that your code has a fault.
Posted by Ian Bale at 4:20 PM




Powered by Gearbox CMS