aspose file tools*
The moose likes Threads and Synchronization and the fly likes Overriden run() Method of Runnable Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Overriden run() Method of Runnable Interface" Watch "Overriden run() Method of Runnable Interface" New topic
Author

Overriden run() Method of Runnable Interface

sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 27
Hi frndz,

Why we won't get any Exception/Error when we are creating user-defined thread with

"synchronized public void run()" implementing runnable interface

where we suppose to override

"public void run()" of Runnable interface in user-defined thread...?



Thanks in advance
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

Because there's nothing wrong with using "synchronized" in that position.

Perhaps you could explain what exception you expected would be thrown, and why?
sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 27
Thanks for reply sir...

Actually the Method signature in Runnable interface is "public void run()",

according to "overridden and Interface" concept, we have to override methods of interface in subclass(child class)
with same Method signature right sir...?

My doubt is that, in Super Class(i.e., in Runnable class) we don't have "synchronized keyword" in method signature

"public void run()"

how can we override run method of super class in subclass using "synchronized keyword" which was not in super class method signature

"synchronized public void run()"

...?
Manuel Petermann
Ranch Hand

Joined: Jul 19, 2011
Posts: 175

The synchronized keyword is simply not belonging to the method signature.
I suggest you read the Java Language Specification for that matter.


Please correct my English.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2402
    
  28

The method signature is differrent than the declaration of the method. The method is declared as synchronized. That doesn't mean that synchronized is part of the signature
sr shashidhar
Greenhorn

Joined: Jan 17, 2013
Posts: 27

Thanks Manuel Petermann and Jayesh A Lalwani...
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
hi,


nice question .Manuel Petermann its really helpful link.


Regards,
James
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriden run() Method of Runnable Interface