* =doc #24435 copy mutable maps before sharing them as messages in java * fix rename * Update DeviceGroup.java * Update DeviceGroup.java
This commit is contained in:
parent
cdecd8b6fe
commit
c023d51367
2 changed files with 14 additions and 2 deletions
|
|
@ -139,8 +139,14 @@ public class DeviceGroup extends AbstractActor {
|
|||
//#query-added
|
||||
|
||||
private void onAllTemperatures(RequestAllTemperatures r) {
|
||||
// since Java collections are mutable, we want to avoid sharing them between actors (since multiple Actors (threads)
|
||||
// modifying the same mutable data-structure is not safe), and perform a defensive copy of the mutable map:
|
||||
//
|
||||
// Feel free to use your favourite immutable data-structures library with Akka in Java applications!
|
||||
Map<ActorRef, String> actorToDeviceIdCopy = new HashMap<>(this.actorToDeviceId);
|
||||
|
||||
getContext().actorOf(DeviceGroupQuery.props(
|
||||
actorToDeviceId, r.requestId, getSender(), new FiniteDuration(3, TimeUnit.SECONDS)));
|
||||
actorToDeviceIdCopy, r.requestId, getSender(), new FiniteDuration(3, TimeUnit.SECONDS)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue