JNDI NamingEnumeration parsing is too slow : what's wrong ?

C

Cram TeXeD

Hi guys !
I get a odd behave in the followings lines (cf. below)
I parse a NamingEnumeration to build up a XML document.
My LDAP searches got back one record.

the instructions look like :
----------------------------------------------------
long startTime = System.currentTimeMillis();
long endLoop = 0;
While ( enum.hasMore()) {

// some relatively heavy stuff

System.currentTimeMillis() - start // get 0-40 ms
endLoop = System.currentTimeMillis();
}
System.currentTimeMillis() - endLoop // get 2500-3000 ms
----------------------------------------------------

I have found out a time gap between the end of the "While block" and
after the block I cant' explain to myself ( about 2500 ms ! ).

Do anybody get an idea ?
Thanks !

Cram

----------------------------------------------------------

full code is :

public static Element createEntry (NamingEnumeration enum,
String baseDn ) throws NamingException {

if ( enum == null )
return null;

Element cache = new DefaultElement("entry-list");


boolean log = false;

// - GET START -
long start = System.currentTimeMillis();
long endLoop = 0;

// - WHILE BLOCK BEGIN -
while (enum.hasMore()) {
SearchResult sr = (SearchResult) enum.next();

String name = sr.getName();

if ( sr.isRelative() ) {

name = name+","+baseDn;

}


Element entry = new DefaultElement("entry");
cache.add(entry);

Element dn = new DefaultElement("dn");
dn.add ( createValue( name ));
entry.add(dn);
Attributes attsVal = sr.getAttributes();
NamingEnumeration attEnum = attsVal.getAll();


while ( attEnum.hasMore() ){
Attribute att = (Attribute) attEnum.next();
// - parsing the attributes object
entry.add(createAttribute( att ));
}
System.out.println( System.currentTimeMillis() - start );
endLoop = System.currentTimeMillis();
}
// - WHILE BLOCK END


// - From the "WHILE BLOCK END" -
System.out.println( System.currentTimeMillis() - endLoop );
// - From the beginning
System.out.println( System.currentTimeMillis() - start );
return cache;
}
 
C

Cram TeXeD

aux environs de Wed, 11 Aug 2004 13:56:16 +0200, Cram TeXeD frappa :
Hi guys !
I get a odd behave in the followings lines (cf. below)
I parse a NamingEnumeration to build up a XML document.
My LDAP searches got back one record.

the instructions look like :
----------------------------------------------------
long startTime = System.currentTimeMillis();
long endLoop = 0;
While ( enum.hasMore()) {

// some relatively heavy stuff

System.currentTimeMillis() - start // get 0-40 ms
endLoop = System.currentTimeMillis();
}
System.currentTimeMillis() - endLoop // get 2500-3000 ms

Ok. I got the solution.
If you take a look at the JNDI doc, it's written
"If an enumeration proceeds to the end--that is, until
hasMoreElements() or hasMore() returns false-- resources will be freed
up automatically and there is no need to explicitly call close()."

But it seems there's a lot of thing just behind the simple hasMore()
== false.

So if you're sur there's only one record in your enumeration, rather
use "next()" method directly and close() just after.


SearchResult sr = (SearchResult) enum.next();
// - blablabla
enum.close()

it take about 40 ms rather than 2500 to do the stuff.

8:0) cram TeXeD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top