How to fix maven warning about thread group still running when using GCSUtil to write files?

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

I wrote a simple program to write a text file to GCS using GCSUtil

I run the program using mvn:exec

mvn exec:java -Dexec.mainClass="dataflow.GCSRunningThreads" -Dexec.args=--output=gs://my-bucket/tmp/hello_world

Maven exits with the following error

[WARNING] thread Thread[pool-1-thread-1,5,dataflow.GCSRunningThreads] was interrupted but is still alive after waiting at least 15000msecs [WARNING] thread Thread[pool-1-thread-1,5,dataflow.GCSRunningThreads] 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=dataflow.GCSRunningThreads,maxpri=10] java.lang.IllegalThreadStateException     at java.lang.ThreadGroup.destroy(ThreadGroup.java:775)     at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:328)     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:57)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:606)     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) [INFO] ------------------------------------------------------------------------

How can I fix this?

回答1:

To fix this you need to shutdown the ExecutorService used by GcsUtil. The following snippet works:

GcsOptions gcsOptions = options.as(GcsOptions.class); gcsOptions.getExecutorService().shutdown(); try {   gcsOptions.getExecutorService().awaitTermination(3, TimeUnit.MINUTES); } catch (InterruptedException e) {   sLogger.error("Thread was interrupted waiting for execution service to shutdown."); }

GCSUtil uses an executor service to handle IO operations asynchronously. We need to shutdown that executor service in order to exit cleanly.



回答2:

Did you try setting below property in your pom (or pass it through command line).

cleanupDaemonThreads = false

Checkout this question, Running daemon with exec-maven-plugin avoiding `IllegalThreadStateException`



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!