Skip to content

Commit

Permalink
Merge pull request #112 from pusher/rejected-execution
Browse files Browse the repository at this point in the history
Synchronize queueOnEventThread
  • Loading branch information
jpatel531 committed May 12, 2016
2 parents 5bf20de + 7c6b86d commit 27a4d71
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/main/java/com/pusher/client/util/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
* {@link #newPublicChannel(String)} creates a new instance of that class every
* time it is called.
*
* - any method that starts with "get", such as {@link #getEventQueue()} returns
* a singleton. These are lazily constructed and their access methods should be
* synchronized for this reason.
*/
public class Factory {

Expand Down Expand Up @@ -97,8 +94,11 @@ public synchronized ChannelManager getChannelManager() {
return channelManager;
}

public void queueOnEventThread(final Runnable r) {
getEventQueue().execute(new Runnable() {
public synchronized void queueOnEventThread(final Runnable r) {
if (eventQueue == null) {
eventQueue = Executors.newSingleThreadExecutor(new DaemonThreadFactory("eventQueue"));
}
eventQueue.execute(new Runnable() {
@Override
public void run() {
synchronized (eventLock) {
Expand All @@ -119,13 +119,6 @@ public synchronized void shutdownThreads() {
}
}

private synchronized ExecutorService getEventQueue() {
if (eventQueue == null) {
eventQueue = Executors.newSingleThreadExecutor(new DaemonThreadFactory("eventQueue"));
}
return eventQueue;
}

private static class DaemonThreadFactory implements ThreadFactory {
private final String name;

Expand Down

0 comments on commit 27a4d71

Please sign in to comment.