In my application cfm I currently load my wirebox as follows.
createObject(‘component’,‘coldbox.system.ioc.Injector’).init(‘epsys.config.coldbox.WireBox’);
My wirebox binder cfc leaches the wirebox injector into the application scope…
Currently I only run this once and have it wrapped in the following conditional.
if( not structKeyExists(application, ‘wireBox’) )
So it only loads once… I removed this condition today and which worked fine on my local machine but when I loaded this to my live server I got lock errors
A timeout occurred while attempting to lock Mapping.MetadataProcessing.epsys.model.UtilityService.
The utillityService is mapped as a singleton in my wirebox binder config…
What am I doing wrong here… do i need the application conditional to prevent the locking errors?
thanks
Alex
Since you are using application.cfm the you must provide your locking. Surround the creation of the injector with a double lock check to prevent race conditions. Why don’t you just upgrade to application.cfc and use the on application start method.
Yes… this would make perfect sense… however our application is so massive and unyielding it will take some time to accomplish this
We will endeavour to complete the long awaited move to application.cfc one day!
thanks for your help!
To expound on Luis’ suggested approach:
if( !structKeyExists(application,“wirebox”) ) {
lock name=“createWireBox” type=“exclusive” {
// Double check to make sure another thread didn’t beat us here
if( !structKeyExists(application,“wirebox”) ) {
application.wirebox = createObject(etc…);
}
}
}
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com