Explain the concept of message passing in java with an example

Whats In Name

Whats In Name

@whats-in-name-KdgM7o Oct 26, 2024
Can someone please explain me the concept of message passing in java with an example?What does object invoking methods on other object means?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Whats In Name

    Whats In Name

    @whats-in-name-KdgM7o May 13, 2013

    -bump
  • Kaustubh Katdare

    Kaustubh Katdare

    @thebigk May 13, 2013

    Whats In Name
    -bump
    Tagging #-Link-Snipped-# , #-Link-Snipped-# to look into this. I miss #-Link-Snipped-# as well.
  • avii

    avii

    @avii-TGGs8o May 13, 2013

    Whats In Name
    Can someone please explain me the concept of message passing in java with an example?
    Tried <a href="https://en.wikipedia.org/wiki/Message_passing" target="_blank" rel="nofollow noopener noreferrer">Message Passing</a> ?
  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn 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😀
  • avii

    avii

    @avii-TGGs8o 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.
  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn May 14, 2013

    avii
    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.
    My bad for creating confusion with concept of shared memory.
    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.
  • sulochana anand

    sulochana anand

    @sulochana-anand-OrGmKr 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”;

    }}
  • Whats In Name

    Whats In Name

    @whats-in-name-KdgM7o May 15, 2013

    sulochana anand
    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”;

    }}
    Is this an example of message passing?
  • sulochana anand

    sulochana anand

    @sulochana-anand-OrGmKr May 15, 2013

    yes as ianoop explained