You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2017/04/10 14:44:12 UTC

Re: apacheds server has thread leak when do some change


Le 10/04/2017 à 08:38, Qing, Hai (Paul PSW CMS R&D) a écrit :
> Hi Sir,
Hi !

>
> I found there was thread leak when do add/remove/nodify/rename entry in this class.

<skip>
> This thread always alive when I integrated the apacheds into my application. Even I called ApacheDsService's stop method in my application.

>
> Any suggestion will be great!

I guess we should make the threads in the pool to be daemon thread, thus
being stopped when the application stops.

Adding this :

        ThreadFactory threadFactory = new ThreadFactory()
        {
            public Thread newThread(Runnable r)
            {
                Thread t = Executors.defaultThreadFactory().newThread(r);
                t.setDaemon(true);
                return t;
            }
        };
       
        executor = new ThreadPoolExecutor( 1, 10, 1000,
TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>( 100 ),
            threadFactory );

should do the work. This code has to be added in the init() function :

    public void init( DirectoryService directoryService ) throws
LdapException
    {
        LOG.info( "Initializing ..." );
        super.init( directoryService );

        evaluator = new ExpressionEvaluator( schemaManager );
       
        ThreadFactory threadFactory = new ThreadFactory()
        {
            public Thread newThread(Runnable r)
            {
                Thread t = Executors.defaultThreadFactory().newThread(r);
                t.setDaemon(true);
                return t;
            }
        };
       
        executor = new ThreadPoolExecutor( 1, 10, 1000,
TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>( 100 ),
            threadFactory );

        this.directoryService.setEventService( new DefaultEventService(
directoryService ) );
        LOG.info( "Initialization complete." );
    }


Can you give it a try ?

Many thanks.

NB : can you create a JIRA for helping us tracking the issue ?

-- 
Emmanuel Lecharny

Symas.com
directory.apache.org