Eclipse hints, tips, and random musings

As a consultant, I told a lot of folks that spawning threads in an EJB container is forbidden by the spec. I told them this, because I read it in the spec. Then somebody called me on it: where in the EJB spec does it say that spawning threads is forbidden?

"Fine", I thought, "I'll find the passage". Unfortunately, I couldn't find it. "Gee", I thought, maybe I was wrong. But I was pretty sure that I wasn't.

My friend Alex Polozoff came to the rescue (as he often does)...

p563 of the EJB v2.1 - 11/12/03 spec states:

The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread, or to change a thread priority or name. The enterprise bean must not attempt to manage thread groups.

These functions are reserved for the EJB container. Allowing the enterprise bean to manage threads would decrease the container ability to properly manage the runtime environment.

So, the spec doesn't exactly say "don't spawn threads", but if you can't start one, it's pretty much saying the same thing.

If you must use a thread, take a look at JSR 237 which defines Work Manager. It's not currently part of the J2EE specification, but it is supported by both BEA and IBM in their respective application server products, so I guess it's a de facto standard.[Read More]