774
Chapter 34: Integrating COM and CORBA Objects in CFML Applications
Using the Application Scope to improve COM performance
The Java call to create a new COM object instance can take substantial time. As a result, creating
COM objects in ColdFusion MX can be substantially slower than in ColdFusion 5. For example,
on some systems, creating a Microsoft Word application object could take over one second using
ColdFusion MX, while on the same system, the overhead of creating the Word object might be
about 200 milliseconds.
Therefore, in ColdFusion MX, you can improve COM performance substantially if you can share
a single COM object in the Application scope among all pages.
Use this technique only if the following are true:
•
The COM object does not need to be created for every request or session. (For session-specific
objects, consider using the technique described in this section with the Session scope in place
of the Application scope.)
•
The COM object is designed for sharing.
Because the object can be accessed from multiple pages and sessions simultaneously, you must
also consider the following threading and locking issues:
•
For best performance, the object should be multithreaded. Otherwise, only one request can
access the object at a time.
•
Lock the code that accesses and modifies common data. In general, you do not have to lock
code that modifies a shared object’s data, including writable properties or file contents, if the
data (as opposed to the object) is not shared by multiple requests. However, specific locking
needs depend on the COM object’s semantics, interface, and implementation.
•
All
cflock
tags in the application that use an Application scope lock share one lock. Therefore,
code that accesses a frequently used COM object inside an Application scope lock can become
a bottleneck and reduce throughput if many users request pages that use the object. You might
be able to avoid some contention by putting code that uses the COM object in named locks;
you must put the code that creates the object in an Application scope lock.
Note:
You can also improve the performance of some COM objects by creating Java stubs, as
described in
“Accessing Complex COM Objects using Java proxies” on page 771
. Using a Java stub
does not improve performance as much as sharing the COM object, but the technique works with all
COM objects. Also, you must generate Java stubs to correctly access complex COM objects that do
not properly make all their features available through the COM IDispatcher interface. Therefore, to
get the greatest performance increase and prevent possible problems, use both techniques.
Example 1: Using the FileSystem object
The following example uses the Microsoft FileSystem Scripting object in the Application scope.
This code creates a user-defined function that returns a structure that consists of the drive letters
and free disk space for all hard drives on the system.
<cfapplication name="comtest" clientmanagement="No" Sessionmanagement="yes">
<!--- Uncomment the following line if you must delete the object from the
Application scope during debugging. Then restore the comments.
This technique is faster than stopping and starting the ColdFusion server. --->
<!--- <cfset structdelete(Application, "fso")> --->
<!--- The getFixedDriveSpace user-defined function returns a structure with
the drive letters as keys and the drive's free space as data for all fixed
drives on a system. The function does not take any arguments --->
Summary of Contents for ColdFusion MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......