>> 
>> furthermore there is another problem: with handler is not possible to use 
>> correctly synchronization block like this
>> 
>> ====
>> Graph g = CommonsGraph.synchronize(g_);
>>     ...
>>  synchronized(g) {
>>       for ( BaseLabeledVertex v2 : g.getVertices() )
>>       {
>>           // do somethings
>>       }
>>  }
>> ====
> 
> sorry I don't understand what you meant/intend to do

I'm trying to explain better. the method getVertices return an Iterator. In a 
multi-thread environment you have to ensure that during the 'for' execution the 
[graph] data structure remains  consistent. 
Also for java collection is the same 
[http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronizedCollection(java.util.Collection)]

So if we use a proxy/handler there is no way to "export" the mutex/lock 
variable used into handler class.

In  our CommonsGraph the variable this.lock is private and is non possible to 
export out of the method, so the user can not utilize the lock to synchronize 
his block.

===
        public Object invoke( Object proxy, Method method, Object[] args )
            throws Throwable
        {
            if ( synchronizedMethods.contains( method ) )
            {
                try
                {
                    synchronized ( this.lock )
                    {
                        return method.invoke( synchronizedMethods, args );
                    }
                }
                catch ( InvocationTargetException e )
                {
                    throw e.getTargetException();
                }
            }
            return method.invoke( synchronizedMethods, args );
        }
===

ciao

--
Marco Speranza <marcospera...@apache.org>
Google Code: http://code.google.com/u/marco.speranza79/

Il giorno 03/mar/2012, alle ore 00:45, Simone Tripodi ha scritto:

>> furthermore there is another problem: with handler is not possible to use 
>> correctly synchronization block like this
>> 
>> ====
>> Graph g = CommonsGraph.synchronize(g_);
>>     ...
>>  synchronized(g) {
>>       for ( BaseLabeledVertex v2 : g.getVertices() )
>>       {
>>           // do somethings
>>       }
>>  }
>> ====
> 
> sorry I don't understand what you meant/intend to do
> 
>> I really think that a synchronized wrapper it's the best solution.
>> 
>> WDYT?
> 
> they sucks because we have to keep them updated while , but if there
> are not alternatives...
> -Simo
> 
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to