How can I transfer a Java object from a client to the workers?

조회 수: 2 (최근 30일)
Matei Blaja
Matei Blaja 2016년 5월 6일
답변: Hornett 2024년 8월 21일
I am using a parfor loop which uses a Java object created on th client before the loop is initialised. How can I transfer the object from the client to the workers?

답변 (1개)

Hornett
Hornett 2024년 8월 21일
In MATLAB, when using a parfor loop, the parallel workers operate in separate processes from the client. This means that objects created on the client, like Java objects, are not automatically available to the workers. To transfer a Java object from the client to the workers, you need to ensure that each worker has access to the necessary data or objects. Here’s how you can handle this:Steps to Transfer a Java Object to Workers
  1. Serializable Java Object: Ensure that the Java object is serializable. MATLAB uses serialization to transfer data to workers, so the Java object must implement the java.io.Serializable interface.
  2. Broadcast the Object: Use the parallel.pool.Constant to broadcast the Java object to the workers. This approach ensures that each worker gets a copy of the object.
  3. Access the Object in parfor: Use the broadcasted object within the parfor loop.

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by