# Stardog connection stuck after executing 20 queries

**URL:** <https://community.stardog.com/t/stardog-connection-stuck-after-executing-20-queries/2011>\
**Category:** Support\
**Created:** [October 16, 2019, 10:29am UTC](https://community.stardog.com/t/stardog-connection-stuck-after-executing-20-queries/2011 "2019-10-16T10:29:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shishir\_Singhal](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/shishir_singhal/32/494_2.png) [@Shishir\_Singhal](https://community.stardog.com/u/Shishir_Singhal)\
**Post date:** [October 16, 2019, 10:29am UTC](https://community.stardog.com/t/stardog-connection-stuck-after-executing-20-queries/2011/1 "2019-10-16T10:29:15Z")

</div>

Hi,  
when I am executing queries in a loop using java. It got stuck after 20 iterations, means after execution of 20 queries.  
code below:

while ((record = reader.readNext()) != null) {  
[//reader.readNext](https://reader.readNext)();  
[//System.out.println](https://System.out.println)(record[0]);  
String p = "\<"+record[0]+"\>";  
System.out.println(p);  
String query = "SELECT (COUNT(\*) as ?total\_triples) { ?s"+p+" ?o }";  
SelectQuery sparQ = connection.select(query);  
System.out.println("query making...!!!");  
SelectQueryResult tupleQueryResult = sparQ.execute();  
System.out.println("query executed...!!!");  
while(tupleQueryResult.hasNext()) {  
BindingSet result = tupleQueryResult.next();  
int val = Literal.intValue((Literal) result.get("total\_triples"));  
System.out.println(val);  
System.out.println(i);  
// predicatesJson.put(record[0], val);  
// System.out.println(Literal.integerValue((Literal) result.get("total\_triples")));

```
		        }
		       
			}

```

it got stuck in "SelectQueryResult tupleQueryResult = sparQ.execute();" line.  
basically, I am reading predicates from a csv file, and for each predicate I am executing a query to find out no of triples associated with this predicate.  
But this program is got stuck after executing 20 iterations.  
Please help me to solve this. ?

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [October 16, 2019, 10:49am UTC](https://community.stardog.com/t/stardog-connection-stuck-after-executing-20-queries/2011/2 "2019-10-16T10:49:14Z")

</div>

I’m in my phone right now so it’s hard to look closely but I don’t thing you’re closing your results. Make sure you close the results after each iteration. It’s auto Closable so you can use a try with resources.

---

<div class="post-metadata">

**Author:** ![Shishir\_Singhal](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/shishir_singhal/32/494_2.png) [@Shishir\_Singhal](https://community.stardog.com/u/Shishir_Singhal)\
**Post date:** [October 16, 2019, 10:51am UTC](https://community.stardog.com/t/stardog-connection-stuck-after-executing-20-queries/2011/3 "2019-10-16T10:51:45Z")

</div>

Thanks @zachary.whitley . It worked....!!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [October 30, 2019, 10:51am UTC](https://community.stardog.com/t/stardog-connection-stuck-after-executing-20-queries/2011/4 "2019-10-30T10:51:46Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
