2

I have a simple database migration JavaExec task that runs a Java class during my build process in gitlab. I have many microservices running identical code. Out of the blue, one of my services suddenly stopped building, getting stuck on this migration step. Here's what the task looks like:

task dbMigrate(type: JavaExec) {
  classpath = sourceSets.main.runtimeClasspath
  main = 'com.blah.Migration'
  doFirst {
      println "Starting dbMigrate"
  }
  doLast {
      println "dbMigrate finished"
  }
}

And the class looks like this:

public static void main(String[] args) {
    AnotherClass.main(args);
    System.out.println("@Migration: complete");
}

Interestingly, this is the output:

Starting dbMigrate
@Migration: complete

The main class finishes, with the last line printing that it's done, but I never get the "dbMigrate finished" log and the build hangs forever.

Update: Adding an explicit System.exit(0) at the end of my main method seems to fix the issue. Why would this be necessary in just this one case?

Colin
  • 650
  • 7
  • 15
  • 3
    without any further information, it looks like something in your `AnotherClass.main(args)` is setting up some listeners, etc. (like servlet).. that's preventing the JVM from exiting.. – riyaz-ali Aug 03 '19 at 06:14
  • You have non-daemon threads left running after `AnotherClass.main`. Check them in Visual VM or similar tool. – madhead Aug 04 '19 at 00:43

0 Answers0