aspose file tools*
The moose likes Threads and Synchronization and the fly likes Is this code starting multiple threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Is this code starting multiple threads" Watch "Is this code starting multiple threads" New topic
Author

Is this code starting multiple threads

Carsten Hoyer
Greenhorn

Joined: Dec 06, 2009
Posts: 3
Hi
This is a very basic Threading question. Does the following code start multiple threads. What I wanted was just make the thread sleep and continue. But using activecount, i can see that the thread number rises.

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3950
    
  17

This code generates and starts one new Thread here:


This bit of code causes that new Thread to sleep:


Steve
Carsten Hoyer
Greenhorn

Joined: Dec 06, 2009
Posts: 3
Ah, ok i forgot to include a running clause in the method. So in the above example. A new thread is only created when the old thread stops running.

R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
Carsten Hoyer wrote:Ah, ok i forgot to include a running clause in the method. So in the above example. A new thread is only created when the old thread stops running.



Both bits of your code will never start more than one thread. If I read your question correctly you want to start a new thread as soon as the previous one stops (running == false). If so the code above does not do that.
Carsten Hoyer
Greenhorn

Joined: Dec 06, 2009
Posts: 3
Thanks for reply. No i wanted that behaviour. One thread that goes on and on. What confused was that activecount() would keep increasing. How do I mark the thread solved?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this code starting multiple threads
 
Similar Threads
regarding threads
doubt regarding Threads?
query related to wait(), notify() and notifyAll() methods
Creating multiple children threads
Threads running on single-core or multi-core?