您怎么想的,不是已经说好是stateless的,你怎么又保存状态呢?
几乎所有的ejb container要cache这个对象的!

解决方案 »

  1.   

    this is a stateful session bean, since you are keeping a state --- a variable oTimeoutAccording to J2EE tutorial:
    A stateless session bean does not maintain a conversational state for a particular client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation. 
      

  2.   

    stateless不能保存状态,而你的bean好像是stateful的,所以才会出现这样的结果。
      

  3.   

    you can try1. call remove() on the bean
    2. set a small timeout on the session bean
      

  4.   

    不用那么麻烦,只要每次调用前都将oTimeout清零就行了
      

  5.   

    我的SessionBean是Stateless的!加remove()和Threed.timeout()都不成功。另外,我想知道这是什么原因?没有人会亲自试验过吗?
      

  6.   

    according to this guy:
    http://groups.google.com/groups?hl=en&threadm=3BBE8207.E8B35F8F%40magnaspeed.net&rnum=16&prev=/groups%3Fq%3Dstateless%2Bsession%2Bbean%2Bstate%26start%3D10%26hl%3Den%26selm%3D3BBE8207.E8B35F8F%2540magnaspeed.net%26rnum%3D16
    The EJB 1.1 spec says that stateless SessionBeans may maintain state
    between method calls, although there is no guarantee that each subsequent method call from a client will be directed to the same SessionBean instance.  So if I understand your question correctly, yes, you should be able to count on the container not resetting the bean instance variables once they have been set to some value by the bean.  Note however that the container is allowed to call ejbRemove() on a stateless SessionBean instance at any time, and also to create new SessionBean instances at will (for example, in response to decreasing or increasing load from clients). In the create case, the container will call ejbCreate() on the newly-created instance.So as long as you set the instance variables in your ejbCreate() method, and clean up any necessary resources in your ejbRemove() method, you can count on the container not messing with your instance variables in the SessionBean instance.  Note that they aren't really read-only, in that your SessionBean code can certainly modify them at any time depending on what you want to do.Randy Schnier
    WebSphere EJB Container developmentDate: 2001-10-05 21:15:22 PST
      

  7.   

    什么是stateless?我认为就是bean developer和别的什么人(系统)有这么一个约定:我的bean里没有保存状态,系统可以据此作任何优化(如:生存期控制,多线程等等。记住实际上ejb container是从你的bean继承了一个类来生成对象的,同时加入了一些系统调用的方法)。也就是说,系统看到这是一个stateless的bean,所以会按管理此类的bean的方法管理你这个对象,他也许会根据这个对象的使用频率决定生成多少个这样的对象,当一个对象使用完后并没有删除而是分配给别的用户使用,所以如果你在对象中存放了状态,系统不知道(因为你告诉他这是个stateless的)。但是如果你想利用这个特性,那你就错了,应为系统分配给你的对象,也许是另外一个,而不是你想要的。好了,我想我说的挺清楚的:)   再看看书吧
      

  8.   

    你说的这种情况是这样产生的:
    当你第一次调用你的Stateless Session Bean,AppServer产生了这个Bean并在你调用后放入缓冲池了,这个Bean的Context中保持了有关这个Bean的环境变量信息(而不是Bean内部的数据);当你第二次调用的时候,AppServer从缓冲池中再把这个Bean激活(因为我想这时除了你,不会有别人在调用它了吧),所以你会发现它保存了上次的状态。你可以试试第三次调用的时候是否为1500。所以如果你应该在每次调用的时候清空你所要设置的状态。
      

  9.   

    我的AppServer是Weblogic,另外我的ejbCreate()函数是这样写的。
      public void ejbCreate()throws CreateException {
        System.out.println("ejbCreate()");
        this.oTimeout = 0;
      }
    另外,测试程序中使用了Remove函数,在控制台中看到只有一次ejbCreate()?
    上述情况是怎么产生的?怎么消除?
      

  10.   

    当然嘛,因为是Statless的,APPServer认为完全没有必要真正去把它给Remove掉,只会将这个Bean放入Cache中等待下一个请求的到来
      

  11.   

    bdsc()老兄说的对,倘若liangxf0022 (liangxf) 不给bdsc()老兄加分的话俺可要说一声不公了:)
    只是bdsc()老兄的一些细节的说法俺不赞成,“实际上ejb  container是从你的bean继承了一个类来生成对象的,同时加入了一些系统调用的方法”,俺不认为是这样的。
      

  12.   

    答对者都有分数拿,不过编写SessionBean的时候要小心了。具体细节还没有清楚。
      

  13.   

    freekevin(kevin):
    还记得那几个空的bean class的方法么
    public void ejbCreate() {}
    public void ejbRemove() {}
    public void ejbActivate() {}
    public void ejbPassivate() {}

    如ejbCreate()里面什么代码都没有你不觉得奇怪吗?
      

  14.   

    里面什么代码都没有为什么会奇怪?因为这个ejb对象不是由你创建的,而是由ejb container创建的。ejb container针对你的这个bean生成了外围代码,一些具体的工作由ejb container完成了。
    再想一下CMP 的entity bean,你的find方法什么也不需要写,可你照样可以找到你所要的entity bean,why?因为所有的工作由ejb container完成了。