0

I have a scala main class

object Job extends App {

         def myProcedure() = {
             sqlu"""CALL `dbName`.`update_history();"""
         }

         implicit val system: ActorSystem = ActorSystem()
         implicit val mat: ActorMaterializer = ActorMaterializer()
         implicit val ec = system.dispatcher
         implicit val session: SlickSession = SlickSession.forConfig("my-mysql")
         val proc = session.db.run(myProcedure))
          
         val terminatedF = proc.flatMap { rec =>
              println("value of the procedure ::" + rec)
              session.close()
              system.terminate()
         }
         Await.result(terminatedF, Duration.Inf)
          println("terminated :::")
     }

I see that the value of rec gets printed, and also terminated ::: i.e. last line also gets printed. However the program does not end. Am I missing anything here ?

user9920500
  • 606
  • 7
  • 21
  • You probably need to "close" or "terminate" that session somehow. I don't know slick, but this snippet doesn't look write to me, leaving the `session` thing just sitting around like this. That's not how code accessing external resources usually looks. To your question, it probably has a thread pool inside, that prevents your program from exiting. Try sifting through slick documentation looking for session management specifically. – Dima Jul 01 '21 at 11:42
  • Thanks for replying, however I figured out the problem. It had nothing to do with slick but had something to do to make JVM exit gracefully – user9920500 Jul 17 '21 at 14:44
  • `System.exit` is _the opposite_ if "exiting gracefully". You should not need it, and the reason you do probably actually does have to do with slick :) – Dima Jul 18 '21 at 15:44

1 Answers1

0

This was a problem with user defined threads.

I used Await.result on the last Future and then did sys.exit(0). Also in build.sbt

I used

fork in run := true

This perfectly works

user9920500
  • 606
  • 7
  • 21