0

I'm using a method in shell script to execute a jar file.

function executeJar(){
 java -cp $BASE_PATH"myjar.jar":$CLASSPATH/* com.sample.main.App config.json
}

Even after the jar completes execution, the java process is still active and not getting killed. Should i kill it manually ? What is a solution for this.

John Thomas
  • 212
  • 3
  • 21
  • This is a very broad question and is lacking vital information such as a snippet of the main method of the java app. I suspect that most likely your program is not doing a System.exit() to signal the JVM to stop (thus also producing an exit code). Please refine the question more. – akortex Apr 16 '18 at 19:23
  • Does the java program stay running when you invoke it directly from the command line? – Bohemian Apr 16 '18 at 21:42

1 Answers1

0
  1. Check if you have any resource still opened (a database connection, an input reader, a socket, etc.). Be sure to .close() those resources or to use try-with-resources statements (they close it for you)

  2. If you are using threads, maybe there's still some thread running. Or maybe something you used has reated threads (a database connection pool for example). Use the Visual VM tool (it comes with every JDK, just type jvisualvm on your console). Open Visual VM, run your app and make sure it won't exit automatically, select your app runtime on the left panel of Visual VM, then monitor the Threads tab on Visual VM. Close your app and check if there's still anything running. https://docs.oracle.com/javase/7/docs/technotes/guides/visualvm/threads.html

  3. If you are running inside Windows, maybe it's only the parent process (a console) that is still running. Try to use javaw instead of java. Difference between java/javaw/javaws

Rafael Odon
  • 1,211
  • 14
  • 20