Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: Collection Processing
    • Labels:
      None

      Description

      If a daemon thread was started within an AE and keeps running independent of the AE processing (e.g. bound to a static variable) it prevents exiting of the CPE.

      Simple test:
      add following class to a AE:

      static class DaemonThread implements Runnable {
      	private static volatile Thread threadInstance;
      	/** Creates a daemon thread if it not already exists. */
      	public synchronized static void startThread() {
      		if ( threadInstance == null ) {
      			threadInstance = new Thread( new DaemonThread(), "TestDaemon" );
      			threadInstance.setDaemon( true );
      			threadInstance.start();
      		}
      	}
      	@Override
      	public void run() {
      		while ( true ) {
      			try { Thread.sleep( 2000 ); } catch ( InterruptedException ie ) {}
      		}
      	}
      }
      

      and call DaemonThread.startThread(); within the process() method.

      After CPE signals collectionProcesscomplete() the application does not exit.
      The reason: in org.apache.uima.collection.impl.cpm.engine.CPMEngine a threadGroupDestroyer thread is created (line 2522) which waits for threads to die. Since it does not check for daemon threads it counts them as normal threads to wait for and thus it waits forever (this can be seen with kill -3 PID to get a JAVA stack trace of all threads under UNIX).

      A workaround would be to put the daemon thread in another ThreadGroup. In the example if you create the tread with

      			ThreadGroup parent = Thread.currentThread().getThreadGroup();
      			while ( parent.getParent() != null )
      				parent = parent.getParent();
      			threadInstance = new Thread( parent, new DaemonThread(), "TestDaemon" );
      

      (in the top most thread group) the CPE exits normally.
      However this is not possible with closed source libraries.

      Thus the threadGroupDestroyer must test for daemon threads. Furthermore the used group.activeCount() (in org.apache.uima.collection.impl.cpm.engine.CPMEngine) should only be used for information purposes - as the javadoc states - not for relying on it as a loop parameter.

      1. CPMEngine.diff
        5 kB
        Timo Boehme
      2. cpm_messages.diff
        0.7 kB
        Timo Boehme

        Activity

        Richard Eckart de Castilho made changes -
        Description If a daemon thread was started within an AE and keeps running independent of the AE processing (e.g. bound to a static variable) it prevents exiting of the CPE.

        Simple test:
        add following class to a AE:
        static class DaemonThread implements Runnable {
        private static volatile Thread threadInstance;
        /** Creates a daemon thread if it not already exists. */
        public synchronized static void startThread() {
        if ( threadInstance == null ) {
        threadInstance = new Thread( new DaemonThread(), "TestDaemon" );
        threadInstance.setDaemon( true );
        threadInstance.start();
        }
        }
        @Override
        public void run() {
        while ( true ) {
        try { Thread.sleep( 2000 ); } catch ( InterruptedException ie ) {}
        }
        }
        }

        and call DaemonThread.startThread(); within the process() method.

        After CPE signals collectionProcesscomplete() the application does not exit.
        The reason: in org.apache.uima.collection.impl.cpm.engine.CPMEngine a threadGroupDestroyer thread is created (line 2522) which waits for threads to die. Since it does not check for daemon threads it counts them as normal threads to wait for and thus it waits forever (this can be seen with kill -3 PID to get a JAVA stack trace of all threads under UNIX).

        A workaround would be to put the daemon thread in another ThreadGroup. In the example if you create the tread with
        ThreadGroup parent = Thread.currentThread().getThreadGroup();
        while ( parent.getParent() != null )
        parent = parent.getParent();
        threadInstance = new Thread( parent, new DaemonThread(), "TestDaemon" );

        (in the top most thread group) the CPE exits normally.
        However this is not possible with closed source libraries.

        Thus the threadGroupDestroyer must test for daemon threads. Furthermore the used group.activeCount() (in org.apache.uima.collection.impl.cpm.engine.CPMEngine) should only be used for information purposes - as the javadoc states - not for relying on it as a loop parameter.
        If a daemon thread was started within an AE and keeps running independent of the AE processing (e.g. bound to a static variable) it prevents exiting of the CPE.

        Simple test:
        add following class to a AE:

        {noformat}
        static class DaemonThread implements Runnable {
        private static volatile Thread threadInstance;
        /** Creates a daemon thread if it not already exists. */
        public synchronized static void startThread() {
        if ( threadInstance == null ) {
        threadInstance = new Thread( new DaemonThread(), "TestDaemon" );
        threadInstance.setDaemon( true );
        threadInstance.start();
        }
        }
        @Override
        public void run() {
        while ( true ) {
        try { Thread.sleep( 2000 ); } catch ( InterruptedException ie ) {}
        }
        }
        }
        {noformat}

        and call DaemonThread.startThread(); within the process() method.

        After CPE signals collectionProcesscomplete() the application does not exit.
        The reason: in org.apache.uima.collection.impl.cpm.engine.CPMEngine a threadGroupDestroyer thread is created (line 2522) which waits for threads to die. Since it does not check for daemon threads it counts them as normal threads to wait for and thus it waits forever (this can be seen with kill -3 PID to get a JAVA stack trace of all threads under UNIX).

        A workaround would be to put the daemon thread in another ThreadGroup. In the example if you create the tread with

        {noformat}
        ThreadGroup parent = Thread.currentThread().getThreadGroup();
        while ( parent.getParent() != null )
        parent = parent.getParent();
        threadInstance = new Thread( parent, new DaemonThread(), "TestDaemon" );
        {noformat}

        (in the top most thread group) the CPE exits normally.
        However this is not possible with closed source libraries.

        Thus the threadGroupDestroyer must test for daemon threads. Furthermore the used group.activeCount() (in org.apache.uima.collection.impl.cpm.engine.CPMEngine) should only be used for information purposes - as the javadoc states - not for relying on it as a loop parameter.
        Timo Boehme made changes -
        Attachment CPMEngine.diff [ 12785520 ]
        Attachment cpm_messages.diff [ 12785521 ]
        Timo Boehme made changes -
        Resolution Won't Fix [ 2 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Marshall Schor made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]
        Timo Boehme created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Timo Boehme
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:

              Development