A ColdFusion component that allows a queue of low-priority tasks to be executed, in serial, in the context of a single CFThread. This way, your low-priority threads do not end up blocking your higher-priority threads.
ColdFusion
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
LICENSE.md
README.md

README.md

AsyncTaskQueue.cfc

by Ben Nadel (on Google+)

ColdFusion threads are awesome because they allow you to run tasks in parallel. This is a particularly excellent optimization for set-it and forget-it style tasks. However, there are some thread limitations to be aware of. Specifically, ColdFusion Standard has a concurrent thread limit of 10. If you launch more than 10 threads, they start to get queued. If you're executing non-essential tasks, it doesn't much matter; but, your non-essential tasks can end up blocking tasks with a higher business priority.

To work within this constraint, I created the AsyncTaskQueue.cfc. This is a ColdFusion component that processes a queue of tasks using a single CFThread. So, rather than spawning a separate thread for each low-priority task, the AsyncTaskQueue.cfc spawns one thread and processes the low-priority tasks, in serial, in the context of the single thread.

While it can be called on its own, I had envisioned the AsyncTaskQueue.cfc as being extended. It has one public method that allows tasks to be added to the internal queue:

  • addTask( callback, callbackArguments ) :: Void

You provide the queue with a callback function and an optional set of arguments to be used when invoking the callback function. This task then gets queued and flushed within a single CFThread tag.