About Question enthuware.oce-ejbd.v6.2.434 :

Moderator: admin

Post Reply
ETS User

About Question enthuware.oce-ejbd.v6.2.434 :

Post by ETS User »

How can doTwo() be called when it says "So the timer creation will fail and the container will discard the instance." when doOne() is called?

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by admin »

Client's call to a method and the actual invocation of the method on the bean instance are disconnected. Therefore, the client call call whatever method is exposed by the interface. It may or may not succeed.

HTH,
Paul.

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by fjwalraven »

In the question it is stated that:
"Given that a client calls doOne() and then doTwo(), which of the following statements are correct?"

The answer:
The client will get an exception when it calls doOne() as well as doTwo().
can be misunderstood as it is not clear whether the client gets an exception when it calls doOne() in combination with doTwo() or that you get an exception from both methods.

So I suggest changing the answer
The client will get an exception when it calls doOne() as well as doTwo().
into
The client will receive an exception from both methods (doOne() and doTwo()).

Regards,
Frits

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by admin »

Thank you for your suggestion, Frits. It has now been updated.

-Paul.

gurpreet_asrgndu
Posts: 55
Joined: Thu Jan 03, 2013 7:51 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by gurpreet_asrgndu »

still not clear about the explanation given to the orginal poster. if the timer creation is failed and the bean instance is discarded how can client call doTwo()?

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by admin »

The client call can put the call to doOne in a try/catch and then call doTwo.

sanju.ait@gmail.com
Posts: 38
Joined: Fri Aug 16, 2013 11:37 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by sanju.ait@gmail.com »

doOne won't throw any exception in this case, tried it.
Also doTwo will print "1" if called within 10 seconds of doOne.

After 10 seconds of of doOne, runtime exception will be thrown because container won't find any timeout method declared in the bean, than only bean instance will be discarded. So if doTwo will be called after 10 seconds of doOnc invocation, will throw exception stating that no ejb found.

sanju.ait@gmail.com
Posts: 38
Joined: Fri Aug 16, 2013 11:37 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by sanju.ait@gmail.com »

Based on above comment explanation.
//LINE 20 in method doTwo() will print 1................... Will be true if called within 10 seconds
//LINE 20 in method doTwo() will print 0................... Will never be called, if called after 10 sec, no ejb will be found.
The print out by //LINE 20 in method doTwo() cannot be predicted with the given information. ... Very True
The client will get an exception when it calls doOne() but not when it calls doTwo(). ... doOne will not throw exception, doTwo will throw exception if called after 10 seconds.

Seems like a messed up question.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by admin »

1. As per the specification, a bean that does not implement TimedObject, it cannot create a timer. So if the exception is not thrown by a container in such a case, then the container is not compliant.
2. This is a stateless bean so it is possible that two calls from a client may even go to a different instances. So even if one instance is discarded, the container will create another instance to service the second call.

HTH,
Paul.

sanju.ait@gmail.com
Posts: 38
Joined: Fri Aug 16, 2013 11:37 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by sanju.ait@gmail.com »

1. As per the specification, a bean that does not implement TimedObject, it cannot create a timer. So if the exception is not thrown by a container in such a case, then the container is not compliant.

REPLY : Its not necessary to implement TimedObject to create timer, method annotated with @Timeout will be suffice.

2. This is a stateless bean so it is possible that two calls from a client may even go to a different instances. So even if one instance is discarded, the container will create another instance to service the second call.

REPLY : Since there is no timeout method in the bean, for every bean if doOne method is called on that bean, that bean will be discarded after 10 second in absence of timeout method.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.434 :

Post by admin »

sanju.ait@gmail.com wrote:1. As per the specification, a bean that does not implement TimedObject, it cannot create a timer. So if the exception is not thrown by a container in such a case, then the container is not compliant.

REPLY : Its not necessary to implement TimedObject to create timer, method annotated with @Timeout will be suffice.
That is correct and that is what the explanation says as well:
Because the bean does not implement javax.ejb.TimedObject and it does not contain @Timeout method either. So the timer creation will fail and the container will discard the instance.
So I am not sure what is the issue.
sanju.ait@gmail.com wrote: 2. This is a stateless bean so it is possible that two calls from a client may even go to a different instances. So even if one instance is discarded, the container will create another instance to service the second call.

REPLY : Since there is no timeout method in the bean, for every bean if doOne method is called on that bean, that bean will be discarded after 10 second in absence of timeout method.
Where did you find this behavior description in the specification? I couldn't find it.

thank you,
Paul.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests