pas-by-reference on remote ejb?

Hi everybody!

I am building a application which consists of ejb. The application consists of:

1) the front layer, i.e. servlets, jsp

2) a front facade, consists of remote stateful ejb

what will hapend if I call a method from a servlet, lets say

MyObj obj =new MyObj("aName");

//some code for to call remote

modifySome(obj);// is located in the remote facade

System.out.println(obj.getSomeName());//(*)

the method modifySome(o) is located in the stateful faced, which is accessed remotely. The method will do this(for example):

publicvoid modifySome(MyObj obj){

obj.setSomeName("a new name");

}

What will hapend when the method returns?

will the object be modify, i.e. what will the output of (*)

what is the difference if I change the remote stateful ejb, to a local stateful ejb?

thanx in advance

/TM

[1206 byte] By [TheMan123a] at [2007-10-2 4:46:15]
# 1

aside from trying out yourself and see the results, it's pass by reference...

you get a copy of the reference to that object and you can perform operation on that object via that reference and the object itself will reflect that... as far as your copy of the reference, once it goes out of scope or is nulled then that method can no access that object... of course the object will still exist while someone has a reference to it... if there are no references, then the object is naturally gc'ed...

btw. local and remote will have the same effect as far as the object is concerned...

- MaxxDmg...

- " He who never sleeps... "

MaxxDmga at 2007-7-16 0:51:06 > top of Java-index,Java Essentials,Java Programming...
# 2
heheh... had to double check... looks like the remote object method parameters are copies of the object while the local are pass by reference... :-Pso number one rule, check the documentation... :D- MaxxDmg... - " He who never sleeps... "
MaxxDmga at 2007-7-16 0:51:06 > top of Java-index,Java Essentials,Java Programming...
# 3

hmmm are you sure of this? what will hapend if the servlet, and jsp are located on machine A, and the remote stateful bean are located on machine B. How can this result in "pass-by-reference"? If its a "pas by refernece", there nust be some kind of stub between them, i.e. a stub which updates the object on machine A when machine B modifies the object.

I have heard that local calls are "pass by reference" BUT remote calls are "pass-by-value". Is this wrong?

best regards

TM

TheMan123a at 2007-7-16 0:51:06 > top of Java-index,Java Essentials,Java Programming...
# 4
> you get a copy of the reference to that object I don't know anything about EJBs, but that's pass by value, not reference. What you describe here is passing the reference by value. The Java language never passes anything by reference.
vanilla_loraxa at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 5

> > you get a copy of the reference to that object

>

> I don't know anything about EJBs, but that's pass by

> value, not reference. What you describe here is

> passing the reference by value. The Java language

> never passes anything by reference.

That's conveniently referred to as "pass-by-reference" for remote objects though it doesn't actually pass by reference.

aniseeda at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 6

> > > you get a copy of the reference to that object

> >

> > I don't know anything about EJBs, but that's pass

> by

> > value, not reference. What you describe here is

> > passing the reference by value. The Java language

> > never passes anything by reference.

>

> That's conveniently referred to as

> "pass-by-reference" for remote objects though it

> doesn't actually pass by reference.

I'll have to take your word on that, as I don't know EJBs, but it sounds ver odd to me.

vanilla_loraxa at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 7

> I'll have to take your word on that, as I don't know

> EJBs, but it sounds ver odd to me.

As mentioned, it's a "convenience" term. RMI/EJB doesn't use pass-by-reference as in the C++/C# definition. Conceptually speaking, it may loosely be thought of as PBR, but it's stretching the term; kind of like saying "objects are passed by or as reference", if you know what I mean...

yawmarka at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 8

Even the RMI trail of the Java tutorial mentions the "pass-by-reference" term loosely.

http://java.sun.com/docs/books/tutorial/rmi/implementing.html

Quote:

The rules governing how arguments and return values are passed are as follows:

- Remote objects are essentially passed by reference. A remote object reference is a stub, which is a client-side proxy that implements the complete set of remote interfaces that the remote object implements.

- Local objects are passed by copy, using object serialization. By default all fields are copied, except those that are marked static or transient. Default serialization behavior can be overridden on a class-by-class basis.

aniseeda at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 9

lol... looks like i could use more sleep...

yes, it's for pass by value for local EJBs and Java methods parameters in general... primatives are pass by value. objects are "passed by value" also, that value being the reference to the object...

for remote EBJ and remote objects ( like in the RMI example) method parameters are " pass by reference", technically the method gets a copy of the original object and any modifications are not reflected in the original...

heheh... :-P

- MaxxDmg...

- " He who never sleeps... "

MaxxDmga at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 10

> yes, it's for pass by value for local EJBs and Java

> methods parameters in general... primatives are pass

> by value. objects are "passed by value" also, that

> value being the reference to the object...

Close...

References are passed by value, objects are not passed at all.

(-:

vanilla_loraxa at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 11

Thanx for all the answers guys! So if I got i right:

When I send a object to a remote EJB, and that EJB modifies this object, this will NOT affect/be visible for the original object, i.e. the object that was first send. Correct?

If I send a objetct to a local EJB, and that EJB modifies this object, this WILL affect the original object. Correct?

besta regards

TM

TheMan123a at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...
# 12
yes, that is correct...- MaxxDmg...- " He who never sleeps... "
MaxxDmga at 2007-7-16 0:51:07 > top of Java-index,Java Essentials,Java Programming...