×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

If this is an interview question, ....

Don't try to to recite definitions. A SessionBean has some methods.
If this call of a method does not leave any information for next call, it is stateless.
If this call accumulates some information for next call, it is stateful.

It is your business that decides whether to be stateful or not. For instance, if you need a SessionBean called TaxCalculatorBean, I
would like to suggest deploying it as stateless. Why? For each method call, we just need input some parameters such as quantity, states(provinces) and get a tax to be charged. The present calculation have nothing to do with next one.

I have not used EJB for some time. I remember that if one wishes to make stateless SessionBean, he needs to declare no instance variables.

"Stateless" is a word we needs to pay attention. As I was a beginner, I asked several professional programmers but they gave me wrong explanations. Maybe because we are not native-English speakers.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / I am a new comer who first enter into this forum. Now I am doing a project using Java and EJB. I want to ask Jabber a question about EJB and say thanks first.
    I am a greenhand to EJB and have studied a lot but still can't understand one issue. When i construct a session bean, what is standand to decide it is stateful or stateless. What is difference between them?
    • If this is an interview question, ....
      Don't try to to recite definitions. A SessionBean has some methods.
      If this call of a method does not leave any information for next call, it is stateless.
      If this call accumulates some information for next call, it is stateful.

      It is your business that decides whether to be stateful or not. For instance, if you need a SessionBean called TaxCalculatorBean, I
      would like to suggest deploying it as stateless. Why? For each method call, we just need input some parameters such as quantity, states(provinces) and get a tax to be charged. The present calculation have nothing to do with next one.

      I have not used EJB for some time. I remember that if one wishes to make stateless SessionBean, he needs to declare no instance variables.

      "Stateless" is a word we needs to pay attention. As I was a beginner, I asked several professional programmers but they gave me wrong explanations. Maybe because we are not native-English speakers.
      • Thank you very much! This isn' t an interview question just a puzzle in my work. BTW, I am still in China who is waiting for the next result after taking IELTS.