File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
I agree. Here's the link:
subject: Some threading issues !!
It's not a secret anymore!