I am not familiar with GWT RPC.
Can I assume your CallEJBImpl class (extending RemoteServiceServlet)
works as a 'normal' servlet in the servlet container, which can be
called in a special way using the GWT API?
If that understanding is correct, I see the following issue:
The servlet container uses a single instance of your servlet to service
all requests. That means your methods could be accessed simultaneously
from different clients. Therefore, you have to be careful when you use
instance variables as they could be accessed concurrently.
A stateful session bean's remote interface (stub) is not designed to be
used concurrently (stateless session bean's remote stub is).
So this code is not correct.
That's why Mahesh asked you where you store the ejb reference.
After looking up the remote interface, you need to store it somewhere so
that it cannot be accessed simultaneously by any other threads.
Usually an HTTP session is used for that.
I hope that sheds some light on what you have observed.
On 14/01/2010 22:32, נחום מורדוכוביץ wrote:
> *i calling the ejb from GWT RPC.*
> **
> **
> package org.yournamehere.server;
>
> import com.google.gwt.user.server.rpc.RemoteServiceServlet;
> import javax.ejb.EJB;
> import myEjb.CounterRemote;
>
> import org.yournamehere.client.CallEJB;
>
> public class CallEJBImpl extends RemoteServiceServlet implements CallEJB
> {
> @EJB
> private CounterRemote counter;
>
> public String myMethod(String s)
> {
> return "Server says: " + s;
> }
>
> public Integer getX()
> {
> return counter.getX();
> }
>
> public void setX(Integer x)
> {
> counter.setX(x);
> }
> }
> *
> *
> On Thu, Jan 14, 2010 at 13:17, Dies Koper <diesk_at_fast.au.fujitsu.com
> <mailto:diesk_at_fast.au.fujitsu.com>> wrote:
>
> Your EJB code looks good. No surprises :)
> How about your servlet/jsp?
>
>
> On 14/01/2010 20:06, נחום מורדוכוביץ wrote:
>
> this is the code.
> * *
> *Counter.java*
> *=============*
> *
> package myEjb;
>
> import javax.annotation.PostConstruct;
> import javax.ejb.Stateful;
>
> @Stateful
> public class Counter implements CounterRemote
> {
> private Integer x;
>
> @PostConstruct
> @Override
> public void initBean()
> {
> this.x = 0;
> }
>
> @Override
> public Integer getX()
> {
> return this.x;
> }
>
> @Override
> public void setX(Integer x)
> {
> this.x = x;
> }
>
> }
> *
>
> The remote interface
> CounterRemote.java
> =================
> package myEjb;
>
> import javax.ejb.Remote;
>
> @Remote
> public interface CounterRemote
> {
>
> @javax.annotation.PostConstruct
> public void initBean();
>
> Integer getX();
>
> void setX(Integer x);
> }
>
> On Thu, Jan 14, 2010 at 07:54, Dies Koper
> <diesk_at_fast.au.fujitsu.com <mailto:diesk_at_fast.au.fujitsu.com>
> <mailto:diesk_at_fast.au.fujitsu.com
> <mailto:diesk_at_fast.au.fujitsu.com>>> wrote:
>
> *Thanks,*
>
> *I wrote a simple stateful ejb that store int number and
> two methods
> getNumber() and setNumber(int x),*
> i'm calling the ejb from two separate sessions (two
> browsers)
> and if i set the number from first session i can see it
> from next
> session by calling getNumber().
> By your answer I understand it should not be so ?
>
>
> Right, it shouldn't. You must be doing something you're not
> telling
> us that make the EJB container think it's the same client.
> Or you're
> keeping the value in a static variable or another shared
> location.
>