wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread class" Watch "Thread class" New topic
Author

Thread class

Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Can someone give an Example of enumerate method in Thread class ?


Understanding is Everything - Peter Lord
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm sure you could figure one out yourself just by looking at the API Other than that, Google returned me this page.


[My Blog]
All roads lead to JavaRanch
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Can anyone give a real life example where this method has been used?



Regards,
Avishkar Nikale
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Here you go: http://faq.javaranch.com/java/ThreadLister
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Other Topic

Another example given in forum which provides an insight into how JVM's might differ with the implementation.

Nice read.
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Lester Burnham wrote:Here you go: http://faq.javaranch.com/java/ThreadLister


Thanks Lester,

Appreciate the help.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Christophe Verré wrote:I'm sure you could figure one out yourself just by looking at the API Other than that, Google returned me this page.


Thankyou Christophe
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

I have another Situation ,

In this case the output from my machine is
[thread 1]
[thread 3]
[thread 2]
I expected it to be
[thread 1]
[thread 2]
[thread 3]
I suspect that I use a quad core - may be the reason ,
Can anyone explain me the reason for that output .
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Pratik D mehta wrote:I suspect that I use a quad core - may be the reason , Can anyone explain me the reason for that output .

It has nothing to do with the number of cores. If there are several threads that can be run, you should not try to predict which one will be run first, and for how long it will be run. That kind of behavior is not guaranteed by the JVM.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
You ought to have started a new thread for that new question, which is too difficult for "beginning Java" anyway, so I shall move this thread.

Remember different threads can be executed at different speeds and produce their output in different orders.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

but
I have synchronized the threads so thread one should execute and than another thread should begin in the order I have called them .
Please clarify this for me I am new to this .
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
You misunderstand what synchronization does. In your code it ensures that only a single thread will be executing the code within the synchronized block (the callme method) at any given time. But it has no influence on the order in which threads enter that block.
Pratik D mehta
Ranch Hand

Joined: Jul 29, 2010
Posts: 121

Thank you , thank you so much Lester and Campbell
I understood it now .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread class