2. Who am I??? Billy Cravens Developing ColdFusion apps since version 4.0 Early involvement with .NET Consultant .. Hire me!!! billy@billycravens.com (713) 408-3052
3. Enough about me… You didn’t come to hear my shameless self-promotion
4. Keys to success presentations Know your audience Make your presentation unique and fun Relevant, useful examples
5. The unthreaded web Request Server does its thing Response Components, functions, AJAX, web services, flushing – still an HTTP request Wait til it’s done SOA: wait on them
9. Some basic examples Single service call: overhead + service time Multiple service calls: overhead + service 1 time + service 2 time + service N time …..
11. Some basic examples Single service call: overhead + service time Multiple service calls: overhead + service 1 time + service 2 time + service N time ….. Each service is synchronous – wait til previous one finished
12. Types of threading in web apps For our purposes, 2 types: Send a task away and leave us alone Perform multiple tasks at the same time and wait for results
13. Run off and leave me alone <cfthread action=“run” name=“NameOfThread”> <!--- whatever code you want goes here ---></cfthread>
14. Limitations of CFThread Doesn’t support concept of call-backs Either the thread runs and is done when its done with no notification anywhere or Parent thread must wait for all child threads to finish and take action then
15. Parallel threads in a page Basic example: a single thread in a page When we just call a thread without joining it to page level thread, it shoots off into never never land So to use results of thread in page: At least one thread to execute Join our threads together Thread results available via threadName or cfthread structure
17. Caveat (Limitation?) No output! Even if you put output tags Can access output (and other neat metadata) by cfdump’ing thread scope Problem: CFDump will strip out HTML Solution: just output threadName.output Especially if you want to CFDump inside your thread!
18. Multiple threads Same process, just keep track of your thread names Pass as a list when joining Loop over cfthread structure to access contents of each Remember scope: Variables set inside of thread do not affect page-level Remember to be “thread safe”! Unpredictable results when you attempt to read variables not local to thread Use attributes scope (remember custom tags?) No control over order data returned Big question: performance enhanced?
19. Watch out! Other variables: can always write over the variable Threads: must always be named unique!!!! Make unique (using CreateUUID() to be safe) But… CFThread scope continues for life of request Loop over list of thread names instead
20. Other limitations No grandparents: can only have one level of child threads Each thread sucks up a request ?? Adobe CF: Standard limited to 10 threads (regardless value set in CF Admin) – rest are queued Must buy Enterprise BlueDragon and Railo other limits Not part of application error handling Error: look at threadScope.error structure
21. Favorite tricks: Timeout a code block Specify timeout to your page level thread Continues when timeout expires Look at status to determine if child thread completed (threadName.status) Doesn’t kill child thread! Only proceeds without it Kill threads in CF Admin or via action=“terminate”
22. Conclusion Synchronous code forces us to wait Asynchronous code lets us take advantage of more resources, enhancing performance Must rethink how data is passed around