Passing clones of object to multiple threads.

Discussions

General J2EE: Passing clones of object to multiple threads.

  1. Hi,

    I want to make it sure whether passing a clone of object to thread will be troublesome or safe. One thing to remember is that my Object does not contain any other object(s) just String properties and getter setters i.e. Simple POJO. ?

  2. Create immutable objects that take arguments into the constructor and are assigned to only final properties.  Don't allow any non-final properties and don't allow any setter methods.  Make sure all the properties are immutable (String is, Calendar is not).  You can use a builder pattern to construct your immutable object easily.  Then have your immutable object be a message in Akka sent to a stateless Actor.  For lists you can use Guava's ImmutableList which is a nice class to enforce immutable by type.