I'm going to explain the issue I am confused about :
The problem with the restrictions in ejb is related to instance TreeCache directly inside the ejb, because TreeCache is a socket listener, thread creator what is forbidden in the ejb especification restrictions.
You have to get the TreeCache reference through JNDI and everything works fine.
Another posibility is the use of jmx to make the reference to the MBean TreeCache, in both cases the creation of TreeCache is not "placed" in the ejb thread but in JBoss.
I did not realize about the problem at that moment.
If you run TreeCache inside JBoss, the best way is always looking it up through MBean service.
Only one more question:
Is this TreeCache MBean called by reference inside ejb?
I mean if we can't use threads control and TreeCache take control of ejb thread (for example in transactions locks)...are we breaking the ejb specs?
If you look it up through the MBean Service and use whats passed back by that then yeah. It's basically a pass by reference. So its no different (to your ejb) than doing a remote or local lookup of an ejb.
We have ejbs use MBeans all the time. The only time you need to be careful is when you get them tangled up... Like for example having an EJB call an entity bean which calls a service which calls the same entity bean... Stuff like that is a problem.
In short EJB -> MBean = fine. Spec is preserved.