Announcement Announcement Module
Collapse
No announcement yet.
Register Shutdown Hook Behavior Diffrent- in stanlone & Spring DM Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Register Shutdown Hook Behavior Diffrent- in stanlone & Spring DM

    I have my initialization like this

    AbstractApplicationContext appContext = new ClassPathXmlApplicationContext("")

    In one of my beans i have a init method which starts thread and a destroy method which has a sysout.

    public void init() {
    thr = new MyThread(service);
    thr.start();
    }


    public void cleanup()
    {
    System.out.println("CLEAN UP BEING CALLED ");

    }


    I register a shutdown hook as follows

    appContext.registerShutdownHook();


    Test cases
    ------------

    In my standalone use cases
    --------------------------
    I get the destroy methods called only after teh threads execution is complete

    In Dm Continer
    ---------------

    When i delete the bundle, destroy method gets called , and thread still continues to run.

    Isn't the behavior different in nature ?

  • #2
    In the standalone case, what's causing destroy to be called? If you're shutting down the VM then it's most likely the shutdown hook that's calling it during JVM shutdown, at which point the thread that you started will also be terminated as part of the VM's shutdown processing.

    In the dm Server case destroy is being called as part of closing the application context for the bundle. This happens as part of the bundle's stop processing. During this shutdown there's nothing in place to stop the thread that your bean started.

    To ensure that this works reliably, and without having to rely upon VM shutdown, I would recommend that, in your bean's destroy method, you update a flag that's frequently checked by MyThread to tell it to stop running.

    Comment


    • #3
      I am exactly following the step u said within the bundle inside Dm server, that is the destroy method sets a flag which is checked in the threads run method .

      But my problem is that I cannot use the same code in my standalone applications. This is because my destroy methods gets called only after the threads execution is complete ..

      What do i do so that the same code is used in both places ?

      Comment


      • #4
        To be more precise , since we are migrating to Spring DM gradually i want the DM behavior in standalone code also , that is i want my destroy method to be called where i can do my thread related cleanup.

        Since destroy method itself is waiting for thread execution to complete . i am stuck :-( . Please help me out

        Comment

        Working...
        X