Cancelling a Directory Search This example searches the directory for objects and abandons the search before it completes. try { // Specify the attributes to match // Ask for objects that have attribute // "sn" == Geisel and the "mail" attribute // ignore case Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("sn", "Geisel")); matchAttrs.put(new BasicAttribute("mail")); // Search for objects with those matching // attributes NamingEnumeration enum = ctx.search("ou=People", matchAttrs); if (enum.hasMore()) { SearchResult entry = (SearchResult)enum.next(); // Abandon rest of results enum.close(); } } catch (NamingException e) { }