问题
For multithread solving, I tried to map a planningId on the identificatication field or getter method.
In our model, some planning entity has the collections of other planning entities or problem facts.
public class User {
@PlanningId
private String username;
...
}
public class CloudComputer {
@PlanningId
private Long id;
//Considering all conditions, possible user changes all over time
//It works well in single thrad, but it does not work in multithread.
private List<User> subtitueUsers = new ArrayList<>();
...
}
In the rebase method, I compared the CloudComputer class.
The memory address of ColudComputer is different according to thread.
But subtitueUsers has the same memory address between this solution and the destination solution.
And sometimes, subtituteusers contains user class having the same memory address between this solution and destination solution.
Is there any way to deep clone a cloud computer including subtituteUsers? Or any other ways to detour this problem?
回答1:
To deep clone, use @DeepPlanningClone
on the subtitueUsers
member (field or getter).
Or, alternatively, use @DeepPlanningClone
on the User
class. Yes, that's actually better here.
(No need to do both.)
来源:https://stackoverflow.com/questions/57355004/how-to-map-a-planningid-annotation-in-collections-for-rebase-method