How to map a planningId annotation in collections for rebase method?

两盒软妹~` 提交于 2019-12-11 03:21:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!