I have used the while (nameResult.hasNext()) pattern as shown in  for close to a decade now,
but I have twice recently run into a situation where TupleQueryResult seems to deadlock within hasNext() when running as a MemoryStore in a webapp deployed via Tomcat.
I see in that "the user is responsible for properly closing a QueryResult", which I believe I do as per , shown below.
In this particular application, the error occurs during the "wrap up phase" of a crawl of about a 1,000 linked data requests. By this point, a handful of "what to crawl" queries had already been run, and a size query was also run for each linked data request. The TupleQueryResult deadlock only appears at the same point in the "wrap up phase", regardless of how large the preceding linked data crawl phase is.
In the prior application, the TupleQueryResult deadlock appeared against a simple <s> <p> ?o query against a graph of a few hundred triples, so the deadlock seems to not depend on graph size or number of prior queries.
In the logging shown below, a "before hasNext()" is the last message.
Any suggestions on how to break through to "free from hasNext()!" ?
Max OS X 10.11.2
Apache Tomcat 8.0.26 web application that depends on Sesame 2.8.8