This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads" Watch "threads" New topic
Author

threads

sri vidya
Greenhorn

Joined: Oct 10, 2000
Posts: 5
Hi,
Please tell me how one thread can start another thread. If possible please give an example.

thanks,
Srividya.

deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
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).]
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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
 
GeeCON Prague 2014
 
subject: threads