This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Some threading issues !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Some threading issues !!" Watch "Some threading issues !!" New topic

Some threading issues !!

Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Hello friends ,
I have some doubts about the threads .So i hope you guys help me out in that for interview :
1) How many threads we can create ?
2)How do thread's stop method work ? Can i restart my stopped thread ?
3) if i create a thread & then null ou the reference to it, what happens to the thread ? does it get interrupted or what ?
4) how should i stop a thread so that i can start a new thread in its place ?
Hoping to hear from you soon,

Success is not doing extraordinary things but doing ordinary things extraordinarily well.
Magnus Andersson

Joined: Mar 03, 2004
Posts: 9
1. As many as you want. Not recommended with too many though.
2. stop is deprecated and should not be used
3. The thread will continue to execute even if you null the reference. When the thread is finished, it will be collected by garbage collector.
4. Let the thread finish, don't stop it. If you want to stop it, make a boolean while(shouldRun) { //loop} and set the shouldRun flag to false to let the thread finish.
Don't get me started about those stupid light bulbs.
subject: Some threading issues !!
It's not a secret anymore!