Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange interview question

 
Lidia Cyc
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get a RemotException for remote beans and a EJBException for local beans

Severin
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

 
Lidia Cyc
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sunil Patil
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, such request won't be simultanious..
ok, thanks a lot for replies.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic