File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Strange interview question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Strange interview question" Watch "Strange interview question" New topic
Author

Strange interview question

Lidia Cyc
Greenhorn

Joined: Aug 05, 2003
Posts: 25
i had a written test as a part of a job interview. and there was a question which sounds very strange for me:

there is a living stateFUL bean in the middle of the business method.
a new client request arrives but the bean is not done yet with the request that arrived earlier. what happens?


what would you say?
Severin Stoeckli
Ranch Hand

Joined: Jul 21, 2004
Posts: 62
You will get a RemotException for remote beans and a EJBException for local beans

Severin
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Lidia,

Severin has correctly identified the exceptions that will be thrown to the second client.

The question is about concurrent access to an instance of a stateful session bean. That is what the spec says about such access (section 7.5.6) :


Clients are not allowed to make concurrent calls to a stateful session object. If a client-invoked business method is in progress on an instance when another client-invoked call, from the same or different client, arrives at the same instance of a stateful session bean class, the container may throw the java.rmi.RemoteException to the second client[4], if the client is a remote client, or the javax.ejb.EJBException, if the client is a local client. This restriction does not apply to a stateless session bean because the container routes each request to a different instance of the session bean class.



Hope it helps,



Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Lidia Cyc
Greenhorn

Joined: Aug 05, 2003
Posts: 25
ok. didn't see this in the books...
still...



i thought the stateful session bean instance is serving one client only. the client which state is actually kept. how comes another client can call the same bean?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

how comes another client can call the same bean?


I could pass the Handle or the reference to some other class/application which could then invoke methods on the bean.

Some containers like Weblogic 6.1 do not throw RemoteException but queue the client request but this could be configured in vendor specific DD to throw RemoteException.

Hope this helps.


Groovy
Sunil Patil
Greenhorn

Joined: Feb 05, 2003
Posts: 15
Hi,

If you want to test this what you can do is write a servlet.In that servlet first check if instance of stateful session bean exists as session attribute and if yes use it or else create new instance and store it in session. Once you get instance of bean call methods on it.
After deploying this servlet try to refresh the page calling servlet repetadly so that it gets multiple requests.

Sunil
Lidia Cyc
Greenhorn

Joined: Aug 05, 2003
Posts: 25
well, such request won't be simultanious..
ok, thanks a lot for replies.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

well, such request won't be simultanious..


They are simultaneous requests,so you get the Exception. Client 1 could get a Handle to SFSB and write it some secondary storage. Client 2 could read the handle from the storage, then both client1 and client2 could be making simulatnoeus requests to the stateful session bean, since both them have handle to the same session bean.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange interview question