lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Goetz <br...@quiotix.com>
Subject Re: multithreading in SegmentsReader
Date Sun, 14 Oct 2001 21:40:27 GMT

>Ok. I guess VMs have improved and now the "conventional wisdom" has 
>changed. It used to be that synchronization by itself was a performance 
>hit, regardless of how it effected other threads. It had something to do 
>with how it was implemented in the VM. But this information is at least a 
>couple of years old.

Doing this:
   for ( ... ) {
     synchronized {
       blah
     }
   }

is considerably slower than this:

   synchronized {
     for ( ... ) {
       blah
     }
   }

Similarly, if you're going to be calling a synchronized method inside an 
inner loop, you will save a lot of time by acquiring the lock outside the 
loop.  Then the synchronization overhead is shortcircuited because the JVM 
sees that we already have the lock and just moves on.


--
Brian Goetz
Quiotix Corporation
brian@quiotix.com           Tel: 650-843-1300            Fax: 650-324-8032

http://www.quiotix.com


Mime
View raw message