Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread class

 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone give an Example of enumerate method in Thread class ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure you could figure one out yourself just by looking at the API Other than that, Google returned me this page.
 
Avishkar Nikale
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone give a real life example where this method has been used?

 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you go: http://faq.javaranch.com/java/ThreadLister
 
Avishkar Nikale
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lester Burnham wrote:Here you go: http://faq.javaranch.com/java/ThreadLister


Thanks Lester,

Appreciate the help.
 
Pratik D mehta
Ranch Hand
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48985
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you , thank you so much Lester and Campbell
I understood it now .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic