Sobes.tech
Junior — Middle

Can you list the different methods of implementing synchronous data exchange in systems?

sobes.tech AI

Answer from AI

Data synchronization in systems can be implemented in several ways:

  • Method calls (RPC): the client calls a server method and waits for a response until the operation is completed.
  • Sockets (TCP/UDP): a connection is established, data is transmitted and received in real-time, and the client is blocked until a response is received.
  • HTTP requests (REST, SOAP): the client sends a request and waits for a response from the server.
  • Synchronous message queues: for example, using JMS with synchronous message receipt.
  • Shared memory or files exchange: a process writes data and waits until another process reads it and responds.

Example of a synchronous method call in Java:

public String fetchData() {
    // call to an external service, blocking the thread
    String response = externalService.getData();
    return response;
}

In this example, the fetchData method blocks execution until it receives a response.