I have a value object, SubordinateUserDTO (DTO == Data Transfer Object), that contains a collection (ArrayList) of another value object, OrgRoleDTO.
In addition to the usual getter/setters, I would like to add methods to add and remove OrgRoleDTO items from the collection. So the SubordinateUserDTO looks like this:
The value object is used to pass data back and forth between a business service object (Usermgmt) and a servlet that support a Flash client. Usermgmt has a method that returns an ArrayList of SubordinateUserDTO, like this:
My servlet creates a Usermgmt object and calls getSubordinateUsers() locally (not an instance variable) in a method that handles all requests. It seems to me this should work fine without synchronizing access to the two collections, but I'm not sure
1) Do I have it right in thinking that I don't need to synchronize access since my servlet creates and accesses the objects in a method and method calls get done on the stack?
2) Of course, the business object should support other callers besides the servlet. Should I make the SubordinateUserDTO.addOrgRole() and removeOrgRole() methods thread safe? If so, how? Also, what about making Usermgmt.getSubordinateUsers() thread safe? Should I do this, or at least warn folks in documentation?
Thanks for any input/feedback that you might offer, Carl
Can you use Vector instead of the ArrayList class? Access to the elements inside a Vector is synchronized. Another tip, use List as the type as in List orgRoleList; that way you can change implementation any time.
Is the business service object an EJB? If not, you may have to worry about threads in the service layer.
Calls from within the servlet are thread safe because the container manages them.