7

我目前正在用 ant 运行一个 java 进程。我只运行一个进程。

当我使用 htop 时,我看到以下信息:

在此处输入图像描述

向右滚动给出: 在此处输入图像描述

基本上,中间部分只包含的 java 进程。

当我这样做时ps aux | grep java,我看到:

$ ps aux | grep java
victor   27982  1.0  1.9 3799504 163112 pts/1  Sl+  02:00   0:06 /usr/bin/java -classpath /usr/share/ant/lib/ant-launcher.jar:/usr/share/java/xmlParserAPIs.jar:/usr/share/java/xercesImpl.jar -Dant.home=/usr/share/ant -Dant.library.dir=/usr/share/ant/lib org.apache.tools.ant.launch.Launcher -cp  tag
victor   28003 19.0  6.6 3523136 544812 pts/1  Sl+  02:00   1:51 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java -Xmx2048m -classpath /home/victor/Giordano/java/lib/commons-math3-3.0.jar:/home/victor/Giordano/java/lib/guava-14.0.1.jar:/home/victor/Giordano/java/lib/joda-time-2.2.jar:/home/victor/Giordano/java/lib/postgresql-9.2-1002.jdbc4.jar -jar /home/victor/Giordano/java/build/jar/Giordano.jar 15
victor   28135  0.0  0.0   9388   924 pts/3    R+   02:10   0:00 grep --color=auto java

知道为什么我的进程在 htop 中有这么多实例吗?

仅供参考,我在四核机器上运行。

如果你们有兴趣,这是我的构建文件。

<project name="Giordano" basedir="." default="main">

  <!-- Keep Eclipse's bin away from our build, use separate folder -->
  <property name="build.dir" value="build" />
  <property name="src.dir" value="src" />
  <property name="lib.dir" value="lib" />
  <property name="classes.dir" value="${build.dir}/classes" />
  <property name="jar.dir" value="${build.dir}/jar" />

  <!-- Main Classes for different processes -->
  <property name="like.main.class" value="com.crowdy.learn.SimilarityLike" />
  <property name="model.main.class" value="com.crowdy.learn.SimilarityModel" />
  <property name="tag.main.class" value="com.crowdy.learn.SimilarityTag" />

  <path id="lib.path">
    <fileset dir="${lib.dir}">
      <include name="*.jar" />
    </fileset>
  </path>

  <target name="clean">
    <delete dir="${build.dir}" />
  </target>

  <target name="compile">
    <mkdir dir="${classes.dir}" />
    <javac srcdir="${src.dir}" destdir="${classes.dir}">
      <classpath refid="lib.path" />
    </javac>
  </target>

  <target name="main">
    <echo>ant is not defined. Use ant like, ant tag or ant model.</echo>
  </target>

  <!-- Running Like -->
  <target name="like" depends="clean,like.run" />

  <!-- Ant properties are not mutable.
       So if we have -Ddb=xyz passed in via cmd line then this will not be defined. -->
  <property name="simThreshold" value="0.05"/>
  <property name="minFeedback" value="40"/>

  <target name="like.jar" depends="compile">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
      <manifest>
        <attribute name="Main-Class" value="${like.main.class}" />
      </manifest>
      <fileset dir="${classes.dir}" includes="**/*.class" />
      <zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
    </jar>
  </target>

  <target name="like.run" depends="like.jar">
    <echo>SETTING parameter simThreshold to ${simThreshold}</echo>
    <echo>SETTING parameter minFeedback to ${minFeedback}</echo>
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true" maxmemory="1024m">
      <classpath refid="lib.path" />
      <arg value="${simThreshold}" />
      <arg value="${minFeedback}" />
    </java>
  </target>

  <!-- Running Model -->
  <target name="model" depends="clean,model.run" />
  <property name="minFeedbackCount" value="15"/>

  <target name="model.jar" depends="compile">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
      <manifest>
        <attribute name="Main-Class" value="${model.main.class}" />
      </manifest>
      <fileset dir="${classes.dir}" includes="**/*.class" />
      <zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
    </jar>
  </target>

  <target name="model.run" depends="model.jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true" maxmemory="1024m">
      <classpath refid="lib.path" />
      <arg value="${minFeedbackCount}" />
    </java>
  </target>

  <!-- Running Tag -->
  <target name="tag" depends="clean,tag.run" />
  <property name="minTagCount" value="20"/>

  <target name="tag.jar" depends="compile">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
      <manifest>
        <attribute name="Main-Class" value="${tag.main.class}" />
      </manifest>
      <fileset dir="${classes.dir}" includes="**/*.class" />
      <zipgroupfileset dir="${lib.dir}" includes="**/*.jar" />
    </jar>
  </target>

  <target name="tag.run" depends="tag.jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true" maxmemory="1024m">
      <classpath refid="lib.path" />
      <arg value="${minTagCount}" />
    </java>
  </target>

</project>
4

2 回答 2

12

Htop 也显示线程。我认为所有这些进程都是您的应用程序创建的线程。如果您不想看到它们,请按 shift+H。

于 2013-04-18T09:52:15.073 回答
0

使用fork attributeinjava task打开一个新的 Java 进程/VM,参见
Ant 手动 java 任务
..“
if enabled triggers the class execution in another VM (disabled by default)
..”

这意味着每个 fork=true 都会打开一个新的 java 进程。

于 2013-04-18T10:40:37.250 回答