• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in threads

 
Vallabhaneni Suresh Kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the need for two classes namely thread and runnable. Why start() is called to run a thread instead of calling run() directly.

Thank you
 
Saket Barve
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the need for two classes namely thread and runnable.


Based on your design requirements, you may want to implement the Runnable interface or extend Thread class.

Why start() is called to run a thread instead of calling run() directly.


The start() method is a signal to the JVM to perform execution of the the newly created thread. The JVM would do so by executing the run() method - which will kick off the actual work.
 
Chandrahas Tore
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If you want your class to use threading & at the same time extend from other class then you can't use Thread class since java doesn't support multiple inheritance. To overcome this you can implement Runnable & extend from other class. For example, if you are creating applet & want to use threading. Second thing is that Runnable contains single method run() which is executed when thread gets CPU, so you have to override only run() method & you can use other methods of Thread class.

The start() method puts the thread in ready state & calls run() when it gets CPU & becomes running. If you directly call run() method it will not start thread.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saying "I have a doubt" is like saying "I have a disbelief." What you probably want to say is "I have a question" or 'Question about threads.'
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"doubt" is very common usage among our Indian friends ... we've talked about how it might have come about in the meaningless forum before. Just translate to "question" on the fly. I have great admiration for anyone who learns a second (or third or fourth) language well enough to get through to me, so I'm more than willing to accept a rather charming idiosyncracy.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I noticed. I thought I would point it out though so he would know. I wonder if it can be traced back to a particular teacher
[ October 06, 2005: Message edited by: Mr. C Lamont Gilbert ]
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are so many teachers around here, so you will have a tough time if you try.

We guys are so used to asking questions when we have a doubt about anything, that even after it gets clarified, the word question gets associated with the word doubt. So, as Mr. James pointed out, "doubt" and "question" are used interchangeably. Translating it on the fly seems to be the best option you got!

English is so universal only because it is so flexible - Isn't it?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So after all that language fun, did you get a good answer about threads? I've wondered if there could be a requirement to extend Thread to override some behavior. I sure haven't had to, and prefer to make Runnables until I find a reason not to.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course. I studied in computers and most of my teachers were from Asia so I can understand the accents easily. Its kind of new to me to understand the text though

Its not a big deal really, but I offer it because sometimes people have mistakes they make that are obvious but nobody bothers to point it out so they never know
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!