Skip to content

Commit

Permalink
do not use the thread pool if it's shutdown
Browse files Browse the repository at this point in the history
should fix koush#256
  • Loading branch information
robUx4 committed Oct 6, 2014
1 parent 5530bb8 commit 864076e
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions AndroidAsync/src/com/koushikdutta/async/AsyncServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ public void removeAllCallbacks(Object scheduled) {
}

private static void wakeup(final SelectorWrapper selector) {
synchronousWorkers.execute(new Runnable() {
@Override
public void run() {
try {
selector.wakeupOnce();
}
catch (Exception e) {
Log.i(LOGTAG, "Selector Exception? L Preview?");
if (!synchronousWorkers.isShutdown()) {
synchronousWorkers.execute(new Runnable() {
@Override
public void run() {
try {
selector.wakeupOnce();
} catch (Exception e) {
Log.i(LOGTAG, "Selector Exception? L Preview?");
}
}
}
});
});
}
}

public Object postDelayed(Runnable runnable, long delay) {
Expand Down Expand Up @@ -399,29 +400,31 @@ public Cancellable connectSocket(final String host, final int port, final Connec
private static ExecutorService synchronousWorkers = Executors.newFixedThreadPool(4);
public Future<InetAddress[]> getAllByName(final String host) {
final SimpleFuture<InetAddress[]> ret = new SimpleFuture<InetAddress[]>();
synchronousWorkers.execute(new Runnable() {
@Override
public void run() {
try {
final InetAddress[] result = InetAddress.getAllByName(host);
if (result == null || result.length == 0)
throw new HostnameResolutionException("no addresses for host");
post(new Runnable() {
@Override
public void run() {
ret.setComplete(null, result);
}
});
} catch (final Exception e) {
post(new Runnable() {
@Override
public void run() {
ret.setComplete(e, null);
}
});
if (!synchronousWorkers.isShutdown()) {
synchronousWorkers.execute(new Runnable() {
@Override
public void run() {
try {
final InetAddress[] result = InetAddress.getAllByName(host);
if (result == null || result.length == 0)
throw new HostnameResolutionException("no addresses for host");
post(new Runnable() {
@Override
public void run() {
ret.setComplete(null, result);
}
});
} catch (final Exception e) {
post(new Runnable() {
@Override
public void run() {
ret.setComplete(e, null);
}
});
}
}
}
});
});
}
return ret;
}

Expand Down

0 comments on commit 864076e

Please sign in to comment.