• 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

threads

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please tell me how one thread can start another thread. If possible please give an example.

thanks,
Srividya.

 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi srividya,
I've written small code for u hope ithelps you.

do get back in case of any doubt
regards
deekasha

[This message has been edited by deekasha gunwant (edited October 12, 2000).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes ofcourse. Any thread is just a piece of code which is run asynchronously. So whatever you are allowed to do in a normal program, you can do the same in the body of the thread also.
Infact, the main method itself is a thread and so any threads started by the main method is a classic example of one thread spawining another one.
Here is a small program I wrote to demonstrate this concept. Since the program is well documented, I will let you explore it. Note how the threads are created.
Thread1( Devil-1 ) --> Creates Thread2( Devil-2 )
Thread2( Devil-2 ) --> Creates Thread3( Devil-3 ) and so on till the room is full of Devils!!.... don't get scared

Hope this helps. Let me know if you still have any questions !!
Ajith
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops!!.. Looks like me and deekasha were trying to answer your question in a non-synchronized manner. This is what happens by the way if you don't get a lock on the object first
Great code deekasha!!
Ajith
reply
    Bookmark Topic Watch Topic
  • New Topic