4 Replies Latest reply on Dec 12, 2009 7:59 AM by armsargis

    ThreadPoolDispatcher shutdown issue

      Hi All in ThreadPoolDispatcher there is code:




         @Destroy
         public void destroy()
         {
            executor.shutdown();
            try
            {
               executor.awaitTermination(5, TimeUnit.SECONDS);
            }
            catch (InterruptedException ie)
            {
               
            }
         }




      Now the question is: if I have long running task how to stop it because simple shutdown() is:


      Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.


      I think code should be like:



          @Destroy
          public void destroy() {
              executor.shutdown();
              try {
                  boolean isDone = executor.awaitTermination(5, TimeUnit.SECONDS);
                  if(!isDone) {
                      executor.shutdownNow();   
                  }
              } catch (InterruptedException ie) {
                  // ignore
              }
          }





      and shutdownNow() javadoc:


      There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.


      It means in my thread I can test for interrupted status and respond correspondingly.


      BTW do have other idea how to stop asynchronous started task?

        • 1. Re: ThreadPoolDispatcher shutdown issue
          kapitanpetko

          Override the default dispatcher with your own component and see how it work out.

          • 2. Re: ThreadPoolDispatcher shutdown issue

            What you mean by 'Override the default dispatcher' it means I need to copy all code from 'default dispatcher' in my component and try it? also there is some package level access code in. 'default dispatcher'.


            And in general:




                    executor.shutdown();
                    try {
                        boolean isDone = executor.awaitTermination(5, TimeUnit.SECONDS);
                        if(!isDone) {
                            executor.shutdownNow();   
                        }
                    } catch (InterruptedException ie) {
                        // ignore
                    }



            I tested it in many situation it was ok.


            • 3. Re: ThreadPoolDispatcher shutdown issue
              kapitanpetko

              Sargis Harutyunyan wrote on Dec 11, 2009 11:14:


              What you mean by 'Override the default dispatcher' it means I need to copy all code from 'default dispatcher' in my component and try it? also there is some package level access code in. 'default dispatcher'.



              I mean define a component with the same name and higher precedence, so that it gets installed instead of the default one. Package level is unfortunate, if that is the case you might have to copy the code. In any case, file a JIRA.

              • 4. Re: ThreadPoolDispatcher shutdown issue

                I have sources of Seam from repo so I will modify directly seam code and build it and deploy in my application to see and test how it works.
                Thanks.