• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Thread start() method

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any one suggest why start method in Thread class is not declared final ?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does it need to be final ?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vishal shekhar:
Can any one suggest why start method in Thread class is not declared final?


Ummm... So it can be overridden?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Ummm... So it can be overloaded?



What would we miss if we overloaded start(); Wont calling start() on thread lose its meaning. It should have been final as I think...

Thanks and Regard,
cmbhatt
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chandra Bhatt:
quote: Ummm... So it can be overloaded.

What would we miss if we overloaded start(); Wont calling start() on thread lose its meaning. It should have been final as I think...


Whoops... I see you quoted my mistaken "overloaded" in the few seconds before I corrected it to "overridden" (and it looks like you didn't notice either ). Sorry, I haven't had enough caffeine today.

Anyway, what if we want start() to do something in addition to starting the thread? That is, do some stuff, and then call super.start()?
[ March 31, 2007: Message edited by: marc weber ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I see you quoted my "overloaded" in the minute or two before I corrected it to, "overridden" (and it looks like you didn't notice either ).



Hey marc!
That's perfect guess, I didn't notice; I felt it was "overridden". But we got our answer out of you, "perform some prior operations if required and call super.start()" Great!

Thanks and Regards,
cmbhatt
 
vishal shekhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Your replies, especially Marc.
 
vishal shekhar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with your explanation. But can't such a thing be done inside the run method( i mean whatever initializations need be performed )?Is there any particular loss in case by not having start as final?
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vishal shekhar:
But can't such a thing be done inside the run method( i mean whatever initializations need be performed )?Is there any particular loss in case by not having start as final?



That goes to the difference between extending Thread and implementing Runnable (which is talked about in detail here). In most cases it's sufficient to implement Runnable (in which case you obviously wouldn't need start to be overridable), but sometimes (rarely) you actually want to alter the behavior of the Thread class, in which case it may be vital to be able to override it.
[ June 29, 2007: Message edited by: Ulf Dittmer ]
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic