This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Synchronized Thread Run Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Synchronized Thread Run Method" Watch "Synchronized Thread Run Method" New topic
Author

Synchronized Thread Run Method

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hello All,

Good Day...

I have a question to ask regarding the following class that I am reading.



From what I have understand the run method of the Thread class was overriden? I hope I'm right?

But I want to ask about the synchronized method in the run method. I'm a bit confused about making the run method synchronize. From my own understanding, making a method synchronize for an object means that other thread that invoke the same object synchronize method is suspended from executing.

I am not sure but does making the run method synchronized means that when the thread scheduler made this thread in running position, all code in the run method is executed and uninterrupted? As I have learned in the Head First Java Book, the execution of the thread depends on the Thread Scheduler.

Please help me clear my doubts.. Thanks to those who will reply.


Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
From what I have understand the run method of the Thread class was overriden?

Yes.

From my own understanding, making a method synchronize for an object means that other thread that invoke the same object synchronize method is suspended from executing.

Correct.

does making the run method synchronized means that when the thread scheduler made this thread in running position, all code in the run method is executed and uninterrupted? As I have learned in the Head First Java Book, the execution of the thread depends on the Thread Scheduler.

No, it can be interrupted. The JVM is free to schedule threads for execution, so any given thread may be interrupted to run other threads (or parts of other threads) first. It would then later be resumed until it runs to completion. But there's nothing the programmer needs to do to accommodate this - the JVM takes care of it.


Ping & DNS - my free Android networking tools app
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hello Ulf,

Thanks for the detailed reply...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronized Thread Run Method