Thursday, November 30, 2017

Coldfusion CFTHROW

Are you using CFThrow to throw custom exception in ColdFusion ? Wait. Read this article before using CFThrow in your application otherwise you will end up in slowing down your application.
Blow is the syntax of CFThrow

To throw an exception we are either required provide object of type java.lang.Throwable or use type information. There is no performance issue if you use object but if you are using type then you might slow down your application performance.

To understand the performance issue we are required to understand how coldfusion work if we you CFTHROW with type.  Coldfusion is responsible to create the exception object to be thrown and coldfusion use type information to create the exception object. The value of TYPE attribute could be the fully qualified java class name or some arbitrary string. Coldfusion always try to first lookup class with the name equal to the value of TYPE attribute using classloader which is slow and synchronized operation. If classloader is able to find class definition then object will be created using loaded definition and thrown else object of CustomException will be thrown.

With the of use some arbitrary value in TYPE attribute instead of fully qualified class name then classloader won't be able to find class definition and store value in cache. So every time we use  CFTHROW classloader will be required to search the class as class doesn't exists.  But if we use valid java class then classloader won't be required to search class the load as it will be in class loader cache after first load operation. 

So, use CFTHROW tag with either object attribute or type attribute with fully qualified class name.

No comments:

Post a Comment

Coldfusion CFTHROW

Are you using CFThrow to throw custom exception in ColdFusion ? Wait. Read this article before using CFThrow in your application otherwis...