Hi David,
I will try to see if it works in constructor but invoking the init() method
is through reflection because we have defined a @BeforeExecute which is
determine which method to be executed before the main execution method and
of course this happen at runtime and through method.invoke()

I will check it out if it works in constructor and post the feedback here

But one more question. Is there any way to join a new created thread to the
currect transaction in which the thread is created? I ask this because in
another usecase we have this issue in which when this thread is starting
there is no transaction associated with it and it complains the context has
been closed or something like that. Now we use UserTransaction to get around
the problem but as you know in this case if the main tx being rolled back
the thread will proceed its way

Lots of thanks


David Blevins wrote:
> 
> Hi Mohammad,
> 
> Instantiating the MyJobImpl class via reflection is fine.  The part I  
> wonder about is invoking it in another thread.  Once the MyJobImpl  
> instance running in another thread it no longer has any relationship  
> to the ASessionBean or it's JNDI environment.  Any JNDI lookups that  
> the MyJobImpl instance needs to do must be done in the same thread as  
> the ASessionBean that created it.  If you moved the lookup into the  
> constructor of the MyJobImpl class, that would work.  Or perhaps call  
> your "init()" method before launching the new thread.
> 
> -David
> 
> On Mar 9, 2009, at 6:34 AM, is_maximum wrote:
> 
>>
>> Hello
>>
>> I have a problem when I want to lookup my session beans.
>> I have declared @EJB on the session bean in which a POJO class will be
>> created using reflection and will be executed in a separate thread.  
>> I did
>> this before without reflection and it works fine but if my class is
>> instantiated at runtime using class.forName() the lookup won't work.  
>> However
>> I'm not sure whether this is because of instantiation or invoking  
>> method
>> with reflection.
>>
>> The class that is instantiating with reflection is actually a batch  
>> job and
>> we can't change the way it will be created and also we need to use  
>> local
>> interfaces in that job. Furthermore a method of that job which is
>> responsible to lookup the SBs is invoked in the same way.
>>
>> to clarify the problem check out the following code:
>>
>> @EJB(name = "ejb/MyEjbRef", beanInterface=MyEjB.class)
>> @Stateless
>> public class ASessionBean implements SessionBean {
>>
>>
>>     public void someMethod() {
>>
>>               MyJob job = MyJobImpl.class.newInstance();
>>               .....
>>     }
>> }
>>
>> MyJobImpl implements MyJob {
>>
>>    @BeforeExecute
>>    public void init() {
>>           //NameNotFoundException occurs here!!!!
>>           // Please note that this method is called using
>> method.invoke(...) rather than normal calling
>>          MyEjb ejb = initialContext.lookup("java:comp/env/ejb/ 
>> MyEjbRef");
>>    }
>>
>>    public void execute() {
>>
>>          //code
>>    }
>> }
>>
>>
>> Is there any workaround to evade this problem or did I missed  
>> something?
>>
>> thanks
>>
>> -----
>> --
>> Regards
>>
>> Mohammad Norouzi
>>
>> Help each other to reach the future faster
>>
>> http://pixelshot.wordpress.com Pixelshot Photoblog
>>
>> http://brainable.blogspot.com Brainable Blog
>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/problem-in-looking-up-local-interfaces-and-reflection-tp22413263p22413263.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
> 
> 
> 


-----
--
Regards

Mohammad Norouzi

Help each other to reach the future faster

http://pixelshot.wordpress.com Pixelshot Photoblog 

http://brainable.blogspot.com Brainable Blog 


-- 
View this message in context: 
http://www.nabble.com/problem-in-looking-up-local-interfaces-and-reflection-tp22413263p22429114.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to