• 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

Is run() thread safe

 
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers ,


if synchronized is added explicitly to run() , then shouldn't it give error.


Because we are changing the nature of run() , which originally designed to be executed by more than one thread at a time . but once it is declared
synchronized only one thread can execute it at a time.


Any thoughts ?


 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because it's a method in a public interface. They are always public.

And no, those methods are not synchronized.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naveen yadav wrote:Hi ranchers ,


if synchronized is added explicitly to run() , then shouldn't it give error.


Because we are changing the nature of run() , which originally designed to be executed by more than one thread at a time . but once it is declared
synchronized only one thread can execute it at a time.


Any thoughts ?




(I am quoting this post because it was originally completely different. Stephan's answers refer to the original version of the post, which no longer exists.)

You'll find that the code you posted does indeed compile.

There are rules for how you can inherit methods from superclasses and interfaces. What you said there isn't those rules.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naveen yadav wrote:

if synchronized is added explicitly to run() , then shouldn't it give error.



synchronized is a perfectly legal keyword here.

Regards,
Dan
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic