directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel L├ęcharny <elecha...@gmail.com>
Subject Re: Threads issue
Date Fri, 28 Nov 2014 09:29:28 GMT
Ok, a clear candidate for your problem :

class AsynchronousRunner implements Runnable
{
    ...

    public void run()
    {
        ...

            while ( !interrupted )
            {
                nextId = aService.getNextId();
               
                if ( nextId != null )
                {
                    threadPool.runTask( new SynchronizeTask( task,
counter, abstractSynchronize, nextId, fromSource ) );
                }
                else
                {
                    try
                    {
                        Thread.sleep( aService.getInterval() );
                    }
                    catch ( InterruptedException e )
                    {
                        AbstractSynchronize.LOGGER.debug(
"Synchronization thread interrupted !" );
                        interrupted = true;
                    }
                }
            }



    public java.util.Map.Entry<String, LscDatasets> getNextId() throws
LscServiceException
    {
        Map<String, LscDatasets> temporaryMap = new HashMap<String,
LscDatasets>( 1 );
       
        if ( sf == null || sf.isCancelled() )
        {
            try
            {
                SearchRequest searchRequest = new SearchRequestImpl();
                searchRequest.addControl( getSearchContinuationControl(
srsc.getServerType() ) );
                searchRequest.setBase( new Dn( getBaseDn() ) );
                searchRequest.setFilter( getFilterAll() );
                searchRequest.setDerefAliases( getAlias(
ldapConn.getDerefAliases() ) );
                searchRequest.setScope( SearchScope.SUBTREE );
                searchRequest.addAttributes( getAttrsId().toArray( new
String[getAttrsId().size()] ) );
                sf = getConnection( ldapConn ).searchAsync( searchRequest );
            }
            ...
        }

        Response searchResponse = null;
        try
        {
            searchResponse = sf.get( 1, TimeUnit.NANOSECONDS );
        }
        catch ( InterruptedException e )
        ...
       
        if ( checkSearchResponse( searchResponse ) )
        {
            SearchResultEntryDecorator sre = ( (
SearchResultEntryDecorator ) searchResponse );
            temporaryMap.put( sre.getObjectName().toString(),
convertEntry( sre.getEntry(), true ) );
           
            return temporaryMap.entrySet().iterator().next();
        }
        else if ( searchResponse != null && searchResponse.getType() ==
MessageTypeEnum.SEARCH_RESULT_DONE )
        {
            LdapResult result = ( ( SearchResultDone ) searchResponse
).getLdapResult();
           
            if ( result.getResultCode() != ResultCodeEnum.SUCCESS )
            {
                throw new LscServiceCommunicationException(
result.getDiagnosticMessage(), null );
            }
           
            sf = null;
        }
       
        return null;
    }


Here, you continuously create new connections, and *never* close any of
them.

Mime
View raw message