-
Can someone please explain me the concept of message passing in java with an example?What does object invoking methods on other object means?0
-
Member • May 13, 2013
-bumpAre you sure? This action cannot be undone. -
Administrator • May 13, 2013
Tagging #-Link-Snipped-# , #-Link-Snipped-# to look into this. I miss #-Link-Snipped-# as well.Whats In Name-bumpAre you sure? This action cannot be undone. -
Member • May 13, 2013
Tried <a href="https://en.wikipedia.org/wiki/Message_passing" target="_blank" rel="nofollow noopener noreferrer">Message Passing</a> ?Whats In NameCan someone please explain me the concept of message passing in java with an example?Are you sure? This action cannot be undone. -
Member • May 14, 2013
I guess you are asking how two thread communicates each other. that is via message passing.
This is generally done with shared memory (class variable, static variable).
If not going inside complexity of multhithreading (It's not complex until you get what it is), use of Getter and Setter can be seen as message passing.
Suppose you have a class of Dog, with two method setBark and getBark, what you do is you create a object of Dog--> set the value in setBark(String how) and then send the object as parameter to recieverObject where you can fetch using getBark()
.
If you go to Multithreading example, you can take producer-consumer problem, Unless producer doen't set the value consumer can't get it. For more you can see this#-Link-Snipped-#
Hope you got what you are asking for😀Are you sure? This action cannot be undone. -
Member • May 14, 2013
Hey wait, shared memory is one of IPC, but in message passing how shared memory is used ? #-Link-Snipped-#
In fact, in distributed systems, due to complexities of sharing memory we go with message passing for IPC. Please correct me if I am wrong.Are you sure? This action cannot be undone. -
Member • May 14, 2013
My bad for creating confusion with concept of shared memory.aviiHey wait, shared memory is one of IPC, but in message passing how shared memory is used ? #-Link-Snipped-#
In fact, in distributed systems, due to complexities of sharing memory we go with message passing for IPC. Please correct me if I am wrong.
Yes, you are right. What I meant to say is solving problems related to message-passing to object.
For example I took of Producer-consumer problem, By algorithm concept both producer and consumer share a common memory and first procedure get lock of shared memory to write things and then consumer checks for lock and when it find unlock then read that memory (Correct me, for this also been a while).
Now, can we implement this in java,
Yes by threading and using setter and getter.(I given the link in previous post)
We can implement message passing in java in following ways...
- In a class, class variable and/or static variable can be used for all object.
- In a program we use object passing through parameters.
- In same/across jvm we can use serialized object for message passing
- In one jvm, between two application system/server properties can be used. like in Tomcat sever we use Application Context to pass object from one application to other.
Are you sure? This action cannot be undone. -
Member • May 14, 2013
Class dog {
String br;
Void Setbarking(String B)
{
B=br;
}
Void Getbarking()
{
s.o.p(B);
}}
Class dogbark
{
Pulic static void main(String args[])
dog d=new dog()
d.B=”bark”;
}}Are you sure? This action cannot be undone. -
Member • May 15, 2013
Is this an example of message passing?sulochana anandClass dog {
String br;
Void Setbarking(String B)
{
B=br;
}
Void Getbarking()
{
s.o.p(B);
}}
Class dogbark
{
Pulic static void main(String args[])
dog d=new dog()
d.B=”bark”;
}}Are you sure? This action cannot be undone. -
Member • May 15, 2013
yes as ianoop explainedAre you sure? This action cannot be undone.