• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Aaargh! Still Weak on Threads

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still having trouble with threads. What happens if a subclass of Thread overrides the start() method?
Can anyone point me to any good on-line material on Threads so I can finally GET this!?
Thanks.
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose that it would depend on how you override the start method. But, you're not supposed to override it. You're supposed to override the run method: public void run();
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you're not supposed to override it. However, if you do, it doesn't seem to do any harm...

When you comment out the call to super.start(), the run() method will not be called. Other wise it works fine......
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The start() method in Thread tells the Thread Scheduler to call the Thread's run() method. It is OK to override this in a subclass. If your overriden method does not include a call to super.start() then no Thread-like behavior will occur, and start() will behave like any other method.
Similarly, Thread's run() is defined but does nothing. So if you don't override the run() method in a subclass of thread, no errors will occur but the thread will do nothing.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pam,
Here are some links to online articles on Threads
Exploring Java, Chapter 6, Threads
Sun tutorial on Threads
Beware the daemons
IBM Redbook: Thin-Client Programming, Introduction to Threads (PDF)
Hope they help.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
Pam Doucette
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huge help. Thanks to all. I've played around with the code, too. Nothing beats first hand experience!
reply
    Bookmark Topic Watch Topic
  • New Topic