Skip to content

Commit

Permalink
#211 polished a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Apr 30, 2015
1 parent 1f74b5c commit 59b7940
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/takes/http/BkTimeable.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public final class BkTimeable implements Back {
/**
* Threads storage.
*/
private final transient Map<Thread, Long> threads;
private final transient Map<Thread, Long> threads =
new ConcurrentHashMap<Thread, Long>(1);

/**
* Ctor.
Expand All @@ -66,7 +67,6 @@ public final class BkTimeable implements Back {
BkTimeable(final Back back, final long msec) {
this.origin = back;
this.latency = msec;
this.threads = new ConcurrentHashMap<Thread, Long>(1);
final Thread monitor = new Thread(
new Runnable() {
@Override
Expand Down Expand Up @@ -99,10 +99,11 @@ public void accept(final Socket socket) throws IOException {
private void check() {
for (final Map.Entry<Thread, Long> entry : this.threads.entrySet()) {
if (System.currentTimeMillis() - entry.getValue() > this.latency) {
if (entry.getKey().isAlive()) {
entry.getKey().interrupt();
final Thread thread = entry.getKey();
if (thread.isAlive()) {
thread.interrupt();
}
this.threads.remove(entry.getKey());
this.threads.remove(thread);
}
}
}
Expand Down

0 comments on commit 59b7940

Please sign in to comment.