0

i run my program using maven with the following command:

mvn exec:java -Dexec.mainClass="some.path.to.my.class"

on a Linux multi-cpu server. when i check the CPU usage, i see that java eats only 1 CPU core. i read somewhere that setting the -server parameter could help.

what parameters do i have to set and how can i pass them using the mvn exec:java command?

ulkas
  • 5,748
  • 5
  • 33
  • 47
  • You could try multithreading to use more than a core in java – aran May 20 '13 at 12:54
  • it depends upon how many concurrently running threads an application have. – Peeyush May 20 '13 at 12:56
  • @AsierAranbarri so how can i do multithreading? do i have to put it into the code? cause i'm using external libraries dedicated to run also on a cluster and they should have it already inside. – ulkas May 20 '13 at 13:07
  • Multithreading is nothing more than executing multiple threads running concurrently. These threads will start consuming more than a core. – aran May 20 '13 at 13:09
  • 1
    If you don't know assume you're not: there's only a few things I know of that attempt to automatically parallise serial code and I don't think any of them have made it into Java yet. If your code isn't creating things that are able to be run off independantly on an arbitrary processor then don't be surprised if that's not happening. – cyborg May 20 '13 at 13:13

2 Answers2

1

You would set it in the commandlineArgs section of the configuration in your pom, as described in the documentation

eg:

 <build>
<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
      <execution>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>maven</executable>
      <commandlineArgs>-server</commandlineArgs>
    </configuration>
  </plugin>
</plugins>

Although I'm not at all sure this is your problem - have you definitely written multithreaded code? You don't need to run the JVM in server mode to use multiple threads.

Tom McIntyre
  • 3,620
  • 2
  • 23
  • 32
  • to do it from the command line it would just be -Dexec.args="-server" – Tom McIntyre May 20 '13 at 12:57
  • thx for answer, but using the commandline parameters didn't help with the 1 core only problem – ulkas May 20 '13 at 13:02
  • OK...as I asked, are you sure you have multithreaded code? Have you used Thread / Executor / ExecutorService anywhere in your code? – Tom McIntyre May 20 '13 at 13:07
  • i'll try to look for it, it is an open source cluster program (apache mahout) which should have use it already itself. – ulkas May 20 '13 at 13:08
1

Processor affinity allows you to bind threads or processes to specific CPU cores.  Java doesn’t have native support for processor affinity but we can set a process affinity using the taskset command. Say we have a Java process running and we want to pin it to a specific CPU. please see following links for more details and find how do this: cpu pinning java