# Java client hangs when executing a SPARQL select query

**URL:** <https://community.stardog.com/t/java-client-hangs-when-executing-a-sparql-select-query/173>\
**Category:** Bug\
**Created:** [March 13, 2017, 12:48pm UTC](https://community.stardog.com/t/java-client-hangs-when-executing-a-sparql-select-query/173 "2017-03-13T12:48:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hmottestad](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/hmottestad/32/19_2.png) [@hmottestad](https://community.stardog.com/u/hmottestad)\
**Post date:** [March 13, 2017, 12:48pm UTC](https://community.stardog.com/t/java-client-hangs-when-executing-a-sparql-select-query/173/1 "2017-03-13T12:48:02Z")

</div>

Hi,

Every once in a while the Java Stardog client is hanging on select queries. After 5 minutes it still hasn't recovered.

After debugging, I think the problem is a timeout in httpclient that is set to 0.

 ![](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/1X/9f465164698dc730bd131e3a1c3732e4ffb7c2e5.png)

---

<div class="post-metadata">

**Author:** ![hmottestad](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/hmottestad/32/19_2.png) [@hmottestad](https://community.stardog.com/u/hmottestad)\
**Post date:** [March 13, 2017, 3:41pm UTC](https://community.stardog.com/t/java-client-hangs-when-executing-a-sparql-select-query/173/2 "2017-03-13T15:41:03Z")

</div>

Server status:

```auto
bash-4.3# ./stardog-admin server status
Backup Storage Directory : .backup
CPU Load : 0.0000 %
Connection Timeout : 1h
Export Storage Directory : .exports
Memory Heap : 140M (Allocated: 338M Max: 910M)
Memory Non-Heap : 108M (Allocated: 111M Max: 1.0G)
Platform Arch : amd64
Platform OS : Linux 4.9.12-moby, Java 1.8.0_111-internal
Query All Graphs : false
Query Timeout : 5m
Stardog Home : /home/stardog/data
Stardog Version : 4.2.3
Strict Parsing : true
Uptime : 25 minutes 50 seconds
Watchdog Enabled : true
Watchdog Port : 5833
Watchdog Remote Access : true
Databases : 
+------------+------------+-------------+-----------------+----------------------+-----------+
| Name | Conn. Open | Trans. Open | Running Queries | Query Avg. Time (ms) | Query/sec |
+------------+------------+-------------+-----------------+----------------------+-----------+
| testSesame | 0 | 0 | 0 | 0.0 | 0.0 |
+------------+------------+-------------+-----------------+----------------------+-----------+

```

---

<div class="post-metadata">

**Author:** ![hmottestad](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/hmottestad/32/19_2.png) [@hmottestad](https://community.stardog.com/u/hmottestad)\
**Post date:** [March 13, 2017, 4:14pm UTC](https://community.stardog.com/t/java-client-hangs-when-executing-a-sparql-select-query/173/3 "2017-03-13T16:14:05Z")

</div>

Seems like I may have been forgetting to close my streams. I’m using Iterations.stream and thought that that would close my stream when it was completed, but it doesn’t.

---

<div class="post-metadata">

**Author:** ![hmottestad](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/hmottestad/32/19_2.png) [@hmottestad](https://community.stardog.com/u/hmottestad)\
**Post date:** [March 13, 2017, 4:45pm UTC](https://community.stardog.com/t/java-client-hangs-when-executing-a-sparql-select-query/173/4 "2017-03-13T16:45:27Z")

</div>

Rewriting my code to close my streams has solved this issue.

```auto
SelectQuery query = connection
    .select("select ?dato where {?a <" + Arkiv.publisertDato + "> ?dato} limit 1")
    .parameter("a", repository.getIdAsResource());

try (Stream<BindingSet> stream = Iterations.stream(query.execute())) {
    return stream
                 .map(next -> DateTime.parse(next.getBinding("dato").getValue().stringValue()))
                 .findAny();
}

```
