• 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

doubt on thread

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i invoke t.run() method the corresponding method in mythread class get excuted but the thread is runned by a thread
named main , not by lal which i have given the name to the thread .



The output that i have got is

RUN BY main i 1 id 1
RUN BY main i 2 id 1
RUN BY main i 3 id 1
RUN BY main i 4 id 1
RUN BY lal i 1 id 8
RUN BY lal i 2 id 8
RUN BY lal i 3 id 8
RUN BY lal i 4 id 8


forgive me if the doubt is silly one

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

when i invoke t.run() method the corresponding method in mythread class get excuted but the thread is runned by a thread
named main , not by lal which i have given the name to the thread .



This is true when the main thread (or ANY thread) calls ANY method of ANY class -- the called method of the class, gets called by the calling thread.

The trick of the Thread class is the start() method. The start() method will start a new thread -- and this new thread will then call the run() method as it's starting point.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic