views:

208

answers:

1

I wanted to grab the concept of "Execution Context class" . I'm refering to this post at http://tinyurl.com/ryjn5o . Can anyone enlighten by explain more on how to create such class ?

+2  A: 

An "execution context class" is just a holder class, created by the top level of your program, which holds all of the things (like the Transaction object in the linked example) from the top level which might be needed.

It's a packaged way to avoid global variables.

Some people believe that even this is kind of skeezy, because if top calls A which calls B which calls C which calls D which needs the top level, you have to pass the context to A, B, and C, which don't otherwise need it.

And so it promotes binding where it wouldn't be needed - A, B, and C are not reusable in a program which doesn't use this context. But it's a perfectly workable alternative to hidden global state, and to the endless proliferation of singletons and other messy things.

Edit: this paragraph is invalid: I do recommend that you use the ExecutionContext class in javax.resource.spi.work ( http://www.j2ee.me/j2ee/1.4/docs/api/javax/resource/spi/work/ExecutionContext.html ), because at least that restricts the binding on the intervening classes to a standard, rather than something app-specific.

CPerkins
any example on how to use javax.resource.spi.work.ExecutionContext ?
cometta
Uhhh, I'm embarrassed here. I made the recommendation hastily, based upon a too-fast reading of a javadoc. It, err, doesn't meet your needs. I'm going to edit my answer to reflect this.
CPerkins