2012-11-20 44 views
22

mavenパッケージフェーズから開始するデーモンスレッドを実行したいと思います。これは私がのpom.xmlに持っているものです。`IllegalThreadStateException`を避けるexec-maven-pluginでデーモンを実行する

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2.1</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>java</goal> 
        </goals> 
       </execution>         
      </executions> 
      <configuration> 
       <mainClass>com.test.Startup</mainClass> 
       <cleanupDaemonThreads>true</cleanupDaemonThreads> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

そしてここでは、クラスのスタートアップの内容です:スレッドが実行を開始しますが、スレッドが実行されている間、コンパイルが停止し

public class Startup { 

    public static class Testing extends Thread { 
     @Override 
     public void run() { 
      while(true) { 
       System.out.println("testing.."); 
      } 
     } 
    } 

    public static void main(String[] list) throws Exception { 
     Testing t = new Testing(); 
     t.setDaemon(true); 
     t.start(); 
    } 
} 

。しばらくすると(タイムアウトなど)スレッドが停止し、コンパイルが続行されます。とにかくバックグラウンドでこのスレッドを開始し、コンパイルを続けますか?

達人からのいくつかの出力:

[WARNING] thread Thread[Thread-1,5,com.test.Startup] was interrupted but is still alive after waiting at least 15000msecs 
[WARNING] thread Thread[Thread-1,5,com.test.Startup] will linger despite being asked to die via interruption 
[WARNING] NOTE: 1 thread(s) did not finish despite being asked to via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied. 
[WARNING] Couldn't destroy threadgroup org.codehaus.mojo.exec.ExecJavaMojo$IsolatedThreadGroup[name=com.test.Startup,maxpri=10] 
java.lang.IllegalThreadStateException 
    at java.lang.ThreadGroup.destroy(ThreadGroup.java:754) 
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:334) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) 

私がいる限りのmavenは、JVMをシャットダウンすると、このスレッドにソケットリスナーを作成し、それがバックグラウンドで暮らすようにする予定ですが、現在それはソケットと思われますコンパイル中にしばらくの間だけオンになります。

+9

さて、このような何かが、一目で 'cleanupDaemonThreads'オプションは、このような行動に責任があるようです。それをfalseに設定しようとしましたか? –

+0

ああ、うまくいったようです。今すぐ実際の実装を行うには.... :)ありがとう! – drodil

+0

ようこそ。 –

答えて

38

質問のコメントセクションで説明した回答を投稿する。 このソリューションは私のために働いた!おかげAndrew Logvinov

cleanupDaemonThreads = falseを

構成タグ

<configuration> <mainClass>com.test.Startup</mainClass> <cleanupDaemonThreads>false</cleanupDaemonThreads> </configuration>

+16

私はexecで同様の問題がありました:java -Dexec.mainClass = "com.test.Startup" -Dexec.cleanupDaemonThreads = false – Yoztastic

関連する問題