File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Concurrency with 2-cores-CPU Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Concurrency with 2-cores-CPU" Watch "Concurrency with 2-cores-CPU" New topic
Author

Concurrency with 2-cores-CPU

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

I have COre2Duo processor but JVM uses only one core. How can I make it to use both of them?


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18118
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

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

Joined: Sep 28, 2004
Posts: 18118
    
  39

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

Joined: Apr 20, 2009
Posts: 804
    
    1

Sure:
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18118
    
  39

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

Joined: Apr 20, 2009
Posts: 804
    
    1

So my code should use both cores on one JVM when I compute some real equations?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18118
    
  39

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concurrency with 2-cores-CPU
 
Similar Threads
The x900 effect ?
Cant use object from another class
Posting to bump up my count...
Text box value is not being completely filled with request attribute
WA #1.....word association