Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

synchonization(this) ..what is the porpose of it?

796251Jul 3 2009 — edited Jul 7 2009
I was reading an example about how to use the media tracker...
[http://java.sun.com/j2se/1.5.0/docs/api/java/awt/MediaTracker.html]

and i have the following question .. what is the purpose of that line ?
public void run() {
            try {
                tracker.waitForID(0);
                tracker.waitForID(1);
            } catch (InterruptedException e) {
                return;
            }
            Thread me = Thread.currentThread();
            while (animator == me) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    break;
                }
                synchronized (this) {  //<----- this line
                    index++;
                    if (index >= anim.length) {
                        index = 0;
                    }
                }
                repaint();
            }
        }
The programe works very well without that line anyway....

Edited by: Pitelk on Jul 3, 2009 10:01 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 4 2009
Added on Jul 3 2009
9 comments
137 views