Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Concurrency with 2-cores-CPU  RSS feed

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have COre2Duo processor but JVM uses only one core. How can I make it to use both of them?
 
Henry Wong
author
Sheriff
Posts: 22851
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the exception of a few older JVMs, the JVM will automatically use all the cores, assuming that there are runnable threads that can be schedulled onto them.

Henry
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have performed a simple test:
2 threads with the infinite loops: for(;;);
1 main thread and 1 user thread.

I looked at the system task manager and I noticed that only one core is on stress. Only 50% of my CPU power was utilized.

What's wrong?
 
Henry Wong
author
Sheriff
Posts: 22851
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have performed a simple test:
2 threads with the infinite loops: for(;;);
1 main thread and 1 user thread.


Can you show us the source for this simple test?

Henry
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure:
 
Henry Wong
author
Sheriff
Posts: 22851
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend that you consider having your threads do real work -- maybe even storing the result in some public instance variable. For on some platforms, the optimizer does a good job removing useless code.

Henry
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So my code should use both cores on one JVM when I compute some real equations?
 
Henry Wong
author
Sheriff
Posts: 22851
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lukas Smith wrote:So my code should use both cores on one JVM when I compute some real equations?


All I can say is to try it -- as I already mentioned, there are some older JVMs that do not use more than one core.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!