07.01.2013 Views

David Defour - Université de Perpignan

David Defour - Université de Perpignan

David Defour - Université de Perpignan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Synchronization Solution<br />

• Solution 1: synchronize on the shared data<br />

public void doSomeOperation() {<br />

synchronized(someSharedObject) {<br />

accessSomeSharedObject();<br />

}<br />

}<br />

• Solution 2: synchronize on the class object<br />

public void doSomeOperation() {<br />

synchronized(SomeThrea<strong>de</strong>dClass.class) {<br />

accessSomeSharedObject();<br />

}<br />

}<br />

731<br />

jeudi 26 janvier 12<br />

– Note that if you synchronize a static method, the lock is the<br />

corresponding Class object, not this

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!