May 10 2013
I do a lot of large processing tasks at LandsofAmerica, and in order to get these scheduled operations to complete in any reasonable amount of time I use the <cfthread> tag to spin off multiple processing threads at a time. Unfortunately, some of these threads take longer to complete than it does to spin up another 5,000 threads in the queue. Once you break that thread limit, ColdFusion to stop accepting new threads and will throw an exception. So I use the method below to make sure that I don't spin up too many threads at one time.
So the trick is to create each thread with a unique name, keep track of those names, and wait for each batch of threads to finish before starting the next batch. And here's your sample code:
/*
We need to keep track of the names of our threads
in order to make sure that we limit our processing
appropriately.
*/
listingThreadNames = "";
/*
And just for fun, we'll create a variable to keep
track of how many threads we want to spin off at any
one time.
*/
numberOfThreads = 10;
/* Loop and start creating threads */
for(i = 1; i LTE 100; i++){
/*
Create a thread name that we'll use to create
the thread and keep track of it. Make sure that
this is unique, or you'll get errors with duplicate
thread names
*/
threadName = "MyThread_#i#";
listingThreadNames = ListAppend(listingThreadNames, threadName);
thread
name = threadName
action = "run"
id = i {
//Do some amazing stuff here
sleep(5000);
}
/* If we've reached the number of defined threads, wait until they all finish. */
if(
listingThreadNames NEQ ""
AND ListLen(listingThreadNames) EQ numberofThreads
){
writeOutput("Waiting on the following threads to finish: #listingThreadNames#<hr />");
/* Join up the threads, which will cause a pause until all the threads are done */
thread
action="join"
name="#listingThreadNames#";
/* Clear out the thread names for use in the next iteration of the loop */
listingThreadNames = "";
}
}
Mar 15 2011
Today I posted on Twitter that I would need to re-evaluate my friendship with anyone who couldn't make it to cf.Objective(). But alright alright... I'll still be your friend, even if you don't make it to cf.Objective. But you should... I just finished working up my schedule, and I'm once again excited to attend a conference. I've been "meaning to attend MAX again" for years, but the last few times I've been it's seemed more a social event, and less an "inspire me to build great things" event. But I still remember hanging out with Jared, Sean, Simeon, and "the rest of the gang" after the first cf.Objective() conference I attended.
After that first cf.Objective() conference is when I first started digging deep into OO development, and when I feel I really started becoming a "programmer" and not just a "developer". The last few years have been very stagnant for me, since I've spent almost all of my time maintaining and attempting to improve or refactor legacy applications. Well it's time to throw my hat back in the ring and go get some smarts.
So here's a list of everything I'm currently set to attend at cf.Objective(). If you're able to make it, please find me and say hello.
At the time that I'm writing this there are still 8 sessions still listed as TBA, so things may change. However, you can already see that there is an extremely diverse range of topics, from unit testing, to JavaScript frameworks, and automated deployment.
Check out the schedule and then register to get your own heavy dose of awesomeness.
Looking forward to seeing you there!
Mar 13 2011
I have a fairly large Mura installation, with a good number of sites on it. I have some customizations that I'd like to be pushed out across all of the sites in my installation. For example, I've changed the way the dspPrimaryNav function works, so that I can prevent child pages from being displayed. Unfortunately, as flexible and customizable as Mura is, there is no good to make global changes to the `contentRenderer.cfc` without losing those changes everytime you perform an update to your core files.
Read more...
Dec 10 2010
I had a need to figure out the next billing date after today, based on a known start date and billing interval. Here's the function I came up with to make it happen.
<cffunction name="getNextBilling" access="public" output="false" returntype="date" >
<cfargument
name="StartDate"
type="date"
required="true"
hint="The date the billing started"
/>
<cfargument
name="BillingInterval"
type="numeric"
required="true"
hint="The number of units for the billing. For example,
if something is billed every 90 days, this value will be 90"
/>
<cfargument
name="IntervalUnit"
type="string"
default="d"
required="false"
hint="The date part for the billing interval. This is the
CF datepart, such as 'd', 'm', 'yyyy', etc. The default is 'd'."
/>
<cfset var TimeFromStart = DateDiff(Arguments.IntervalUnit, StartDate, Now()) />
<cfreturn DateAdd(Arguments.IntervalUnit, TimeFromStart + Arguments.BillingInterval - (TimeFromStart MOD Arguments.BillingInterval), Arguments.Startdate) />
</cffunction>
Let me know if you spot a problem with the solution, or have suggestions for improvement.
Dec 8 2010
It's horribly annoying trying to find a file on your file system when it's buried folders deep in your project, on who knows which hard drive. In an effort to make this easier I scoured the interwebs for you, and found a solution.
Read more...
6-7-2010
3-22-2010
12-11-2009
12-2-2009
12-2-2009