diff --git a/src/main/java/io/socket/thread/EventThread.java b/src/main/java/io/socket/thread/EventThread.java index 90f7aec7..43781e2e 100644 --- a/src/main/java/io/socket/thread/EventThread.java +++ b/src/main/java/io/socket/thread/EventThread.java @@ -27,10 +27,7 @@ public Thread newThread(Runnable runnable) { private static EventThread thread; - private static ExecutorService service; - - private static int counter = 0; - + private static final ExecutorService service = Executors.newSingleThreadExecutor(THREAD_FACTORY); private EventThread(Runnable runnable) { super(runnable); @@ -64,16 +61,7 @@ public static void exec(Runnable task) { * @param task */ public static void nextTick(final Runnable task) { - ExecutorService executor; - synchronized (EventThread.class) { - counter++; - if (service == null) { - service = Executors.newSingleThreadExecutor(THREAD_FACTORY); - } - executor = service; - } - - executor.execute(new Runnable() { + service.execute(new Runnable() { @Override public void run() { try { @@ -81,15 +69,6 @@ public void run() { } catch (Throwable t) { logger.log(Level.SEVERE, "Task threw exception", t); throw t; - } finally { - synchronized (EventThread.class) { - counter--; - if (counter == 0) { - service.shutdown(); - service = null; - thread = null; - } - } } } });