aspose file tools*
The moose likes Threads and Synchronization and the fly likes Writing Software for Multicore System Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Writing Software for Multicore System" Watch "Writing Software for Multicore System" New topic
Author

Writing Software for Multicore System

Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
If i want to utilise the multicore CPU as much as possible, is it simply by making my program spawning as much threads as possible? Assuming I can break down my program into parallell running units and it handles thread-safety issue manually.

If yes, then how many threads are optimal? Since I cannot foresee the number of cores the target systems will have.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3971
    
  17

How many threads are optimal? That depends a lot on the program - what it does, and how many processors are available. There is no way to really predict it. The best thing you can do is make your program with a configurable number of Threads (a Thread Pool comes to mind - see ExecutorService for more). Then test the number of Threads that get you the correct performance.

You can also get a bit more detailed, depending on the work that you are doing. You may need to balance threads that 'get' data (producers) and threads that use data (consumers) - or threads that use I/O like disks, or databases, with those that don't. So there is no magic number, you have to code and test to see.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing Software for Multicore System
 
Similar Threads
Death of Java, film at 11
Dr Dobbs on functional languages
parallelism in a for loop and using java 5 concurrency
Java multiprocess communication with each process running multiple threads
50 MB RAM normal for 1500 lines of code?