• Post Reply Bookmark Topic Watch Topic
  • New Topic

ejbCreate

 
Ajai
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have 2 questions.
1. It is a recommended practice that we should do the look ups in ejbCreate method.But should we create the bean also in the ejbCrate method. Say a MDB uses some utility ejb say UtilEJB.
Should I just get the home interface in ejbCreate or I should also call create method for UtilEJB?

2. How about reading a property file, if contents of the file may change while server is running.In this case I believe using a Singleton for reading properties file or reading it in ejbCreate will be same e.g. in both cases we will have to restart the server to see the cahnges.


Any suggestions?

Thks.
 
Brian Tinnel
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On #1, If UtilEJB is stateless then calling create during ejbCreate should be fine.

On #2, My preference would be to put the configuration information in a database table and use that during initialization. If you want to update the table and don't want your bean to use the new information, there are ways to do that. But, if you must use a file.... Reading it during ejbCreate, doesn't guarantee that a change will not be reflected until restart. Let's say you change the file. Any MDBs currently in the pool will be using the old values. But, if the server needs to create new entries in the pool, they will read the new values. In that case, a Singleton is probably your best bet.
 
Ajai
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian,

Thanks for your reply.
  • What if the UtilEJB is statefull?

  • In the answer to second question you mentioned
    "If you want to update the table and don't want your bean to use the new information, there are ways to do that"
    Can you please tell me which ways you are reffering to?

    Thanks
     
    Brian Tinnel
    Ranch Hand
    Posts: 69
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If UtilEJB is state then you could have a problem with a stateless bean as a wrapper around a stateful bean. I encountered a problem with this because under JBoss the stateful bean was passivated after 10 minutes of inactivity, and then removed after 30 minutes of inactivity (I think those are the right numbers). So, when my app was idle for more than 30 minutes, attempts to access the stateful bean from the stateless one failed.

    For number 2, one thing I have done is to put a timestamp in the table. Then the queries look for configuration that is less than or equal to the current time. If I don't want a config setting to take effect for a day or two, I just set the timestamp to the future. I have also used version numbers, but that is a bit trickier because you need some way of telling the beans which version to use.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!