• 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

using RUN() in Thread class

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i have one doubt regarding the use of Thread class

if i am extending a Thread class and creating some new class., is it possible to write more than one RUN() method.,

if it is not possible,and if i want to write different implementation for each thread object i create., then what i need to do.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot have more than one method with the same name and the same parameters inside one class. So no, you cannot create multiple public void run() methods in the same class. There would be no way to tell those methods apart, how would you expect Java to know which one to use?

Create multiple classes, each with their own run() method.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And just to add to what was already said, in the specific case of Thread, you will be better off implementing Runnable and passing it to created threads rather than extending Thread and overriding its run() method.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the technical language of computer science (java dialect), the way they say what Jesper just stated is that in a given class definition, no 2 methods can have the same "signature".

If you don't know what a Java object signature is, I recommend studying it and the notation that they use to describe signatures. It's not just interesting - a lot of Java APIs specify what signature an object, property, or method has to have in order to be acceptable.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nagaraja swamy wrote:is it possible to write more than one RUN() method


<nitpick>
The fact is that you don't want to write even one RUN() method, because the correct name is run().
</nitpick>

Winston
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic