[concurrency-interest] synchronize design

Joe Bowbeer joe.bowbeer at gmail.com
Wed Feb 7 13:47:51 EST 2007


The information is still too sketchy to provide much concrete advise.
But I can think of three things:

1. If possible, make the fields of Session 'final'.

2. See JCiP for a thorough discussion of protecting mutable state and
GuardedBy documentation.

3. For two ReadWriteLock examples, see the javadoc for

 java.util.concurrent.locks.ReentrantReadWriteLock

You could for example add the R-W lock to Session and require all
clients to use it:

 public final ReadWriteLock rwl = new ReentrantReadWriteLock();

(Or you could build it into every Session method, or you could
implement Session as an active object, as Peter suggests, so that all
requests are processed by a single thread dedicated to Session...)


On 2/7/07, sidali ikhlef <s_ikhlef at hotmail.com> wrote:
>
> First thank you for all your suggestions. I will explore in details all
> propositions. Before that, i want to give more details about the
> synchronization problem:
>
> I have four agents or simply threads, in the contex of intelligent tutoring
> systems, that i launch first. When i create the agents, i give them the
> shared resource throw constructor called Session. Session includes all
> learner session informations. Each agent can reads or writes on Session.
>
> public class Session {
>
>     private CurrentActivity currentActivity = null;
>     private Environment environment = null;
>     private GraphBuilder gb = null;
> }
>
> CurrentActivity can be extyended by many types
> CurrentProblemSolvingActivity, CurrentDemonstrationActivity ... etc.
>
> 1-Where exactly can i perform high leve synchronization mecanisms. On
> Session class, on ConcurrentActivity class, on each extended classes or on
> thread bodies?
>
> 2- Is it possible to synchronize using getters like:
>     public Activity getCurrentActivity(){
>     return  currentActivity;
>     }
> and how?
>
> Regards.
>


More information about the Concurrency-interest mailing list