directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From S├ębastien Bahloul <sebastien.bahl...@gmail.com>
Subject Re: Threads issue
Date Fri, 28 Nov 2014 09:39:01 GMT
Hi Emmanuel,

Ok, I'll look at that today.

Thanks,

Sebastien BAHLOUL
IAM / Security specialist
Ldap Synchronization Connector : http://lsc-project.org
Blog : http://sbahloul.wordpress.com/

2014-11-28 10:29 GMT+01:00 Emmanuel L├ęcharny <elecharny@gmail.com>:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message