Results 1 to 3 of 3

Thread: Why linux won't let my java program to use all cpus?

  1. #1
    Join Date
    Feb 2012
    Beans
    75

    Why linux won't let my java program to use all cpus?

    Why linux won't let my java program to use all cpus?

  2. #2
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Why linux won't let my java program to use all cpus?

    Can you provide us with a minimal working example that shows the issue?

    Using more than one core at a time is supported by the JVM, so it should work. Did you split the computation-heavy task that you are trying to perform into multiple threads? This is a requirement for using more than one cpu. If you do use multiple threads already, are there probably any locks in your program that prevent the threads from actively running in parallel?

    At the very least, the garbage collector is multi-threaded. So even if your program does not use multiple threads, the garbage collector will use more than one cpu at a time.

  3. #3
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: Why linux won't let my java program to use all cpus?

    Are you using threads just now? Where is the data coming from and going to?
    If your program is single-threaded, then no number of cores on your machine is going to make it run any faster. Without using multiple threads or processes (or something other than the one process running), you won't be able to achieve n*100% usage on a n-core machine.
    Java does have threading support, but it won't automatically parallelize your code for you. Another important detail to note is that Java threads are not the same as system threads. The JVM often has its own thread scheduler that tries to put Java threads onto actual system threads in a way that's fair, but there's no actual guarantee that it will do so.
    Check this javadoc.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •