Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is message passing?

Tags:

java

What is message passing in Java? If you could, please provide an example.

like image 887
Pavalesh Avatar asked Jul 11 '10 08:07

Pavalesh


1 Answers

Message Passing In Java

  • When a thread sends a message (an object) to another thread.

  • Used for thread communication and synchronization in environments where the threads do not have shared memory Hence the threads cannot share semaphores or monitors and cannot use shared variables to communicate. Message passing can still be used, of course, in a shared memory platform.

  • Messages are sent through a channel with an operation like send(channel, message) and received from a channel with an operation like receive(channel, message). Messages can be passed synchronously, meaning the sender blocks until the received does a receive and the receiver blocks until the sender does a send. Since the sender and receiver are at specific known points in their code at a known specific instant of time, synchronous message passing is also called a simple rendezvous with a one-way flow of information from the sender to the receiver. An example is a chess game agent. The agents can process messages synchronously, since they'll be handshaking throughout the entire game.

  • In asynchronous message passing, the sender does not block. If there is not a receiver waiting to receive the message, the message is queued or buffered. The receiver still blocks if there is no queued or buffered message when a receive is executed.

like image 140
Romain Hippeau Avatar answered Sep 25 '22 16:09

Romain Hippeau