0

I am using Neo4j embedded in my Scala project. I have been including

ShutdownHookThread {
    shutdown(ds)
    }

the above piece of code in each and every function before the beginning of transaction. Do I need to include it in every function. What happens if I don't include it?

yAsH
  • 3,367
  • 8
  • 36
  • 67

1 Answers1

2

ShutdownHookThread registers a piece of code to be executed when your application is about to exit. You need to use it only once - somewhere in your app bootstrap code, cause there is no sense to shutdown the database more than one time.

Yaroslav
  • 4,543
  • 5
  • 26
  • 36
  • Different functions are called for different user actions. So, once an action is performed by the user I need to shutdown the database right? – yAsH Sep 05 '13 at 10:46
  • Usually the database is opened once on app startup and closed once on app shutdown. There is no sense to repeat that on every user action - slows it down and causes concurrency issues. – Yaroslav Sep 05 '13 at 11:06
  • what do you mean by app startup and closing? Mine is a web application! – yAsH Sep 05 '13 at 11:19
  • In context of java web applications those correspond to the methods `contextInitialized` and `contextDestroyed` of the `ServletContextListener`. – Yaroslav Sep 05 '13 at 11:34