How to wait until a file is downloaded or why cfthread is a bad idea within a cfloop

How to wait until a file is downloaded or why cfthread is a bad idea within a cfloop

I just run into an issue where one of our servers was totally bogged down when users started to download 100 or more files. See, the problem is that we had to check that each file was downloaded successfully before processing with the rest of the code. In other words;

1) Query for files that need to be downloaded
2) Loop over the records
3) Within loop download the file
4) check if file has been downloaded successfully
5) continue with the code.

In Coldfusion (or CFML to be general) your code would look like:

<cfloop query…>
<cfthread…>
<cfhttp…>
<cfthread action=”join”…>

As I mentioned above, we need to check if the file has been downloaded successfully before continuing with the next download. That’s why  there is a cfthread in this code.  Now, while this might be a good idea with small download, it has a hazardous effect if you will trigger 1000 downloads, which again would create 1000 threads!!!

So, there are actually 2 things I’ve learned from this:

  1. There is no need for the cfthread. Since cfhttp will halt the code process until the file has been downloaded, creating the thread is not needed.
  2. Creating a thread within the iteration of your resultset (cfloop) is a VERY  bad idea!

Trusted by over 2,000 organizations with millions of emails

Helpmonks helps us answer customer emails at lighting speed
We couldn't do our job without Helpmonks!
Helpmonks, the best thing since sliced bread
Excellent option for collaborating email amongst your team
A good platform that is here to grow and help you grow
Helpmonks is a great tool that our company utilizes and depends on
Great shared inbox for the team
Fantastic email support service for any business
Easy to navigate and catalog data for specific users
Solid Helpdesk software w/ responsive customer support
A really good solution to manage customer support mailbox
Good support, useful features

One more thing...

Helpmonks gives you the ability tocollaborate as a groupin your shared mailbox, features aTeam To-Do App, powerfulCustomer Relationship Management (CRM)capabilities, a completeLive-Chat tool, a mighty Email Marketing Platform that includes sending ofemail campaignsandemail automation, collision detection, email tracking, reminders, mentions, custom fields, custom applications, customer satisfaction ratings, Single-Sign-On (SSO) & SAML authentication, Trello, Zapier, Slack, an API, and much more.

Check outthe complete feature listor sign up for afree 30-day shared inbox trial now