java-ee – 使用exec-maven-plugin运行守护程序,避免’IllegalThreadStateException’ - 代码日志

java-ee – 使用exec-maven-plugin运行守护程序,避免’IllegalThreadStateException’

我想运行一个守护进程线程,应该从maven包开始。这是我在pom.xml中的

<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();
    }
}

线程开始运行,但是在线程运行时,编译停止。经过一段时间(超时或某事),线程停止并且编译继续。有没有反正我可以得到这个线程从背景开始,使编译继续自己?

maven的一些输出:

[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,但是当前似乎套接字在编译期间将只有一段时间。

发布问题评论部分中讨论的答案。
这个解决方案为我工作!谢谢Andrew Logvinov

cleanupDaemonThreads = false

在配置标签中这样的东西

<结构>
       < mainClass> com.test.Startup< / mainClass>
       < cleanupDaemonThreads&GT假LT; / cleanupDaemonThreads>
< /结构>

http://stackoverflow.com/questions/13471519/running-daemon-with-exec-maven-plugin-avoiding-illegalthreadstateexception

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:java-ee – 使用exec-maven-plugin运行守护程序,避免’IllegalThreadStateException’