• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Synchronized Thread Run Method

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ulf,

Thanks for the detailed reply...
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic