mwkirk / javapns

Test import of svn javapns repo from Google Code
3 stars 0 forks source link

Race Condition when sending large amount of Push Notifications #98

Closed mwkirk closed 11 years ago

mwkirk commented 11 years ago

Original author: angela.s...@gmail.com (January 11, 2012 07:52:38)

Hi all

We are using your Framework in Production to send large amounts of Push Notifications. We had a strange behaviour that suddenly the whole processing of sending the messages stopped.

With the help of a heap dump we saw that a thread in your framework was waiting/blocking.

"task-scheduler-4" prio=10 tid=0x00002aaaf88b3000 nid=0x741e in Object.wait() [0x0000000042d12000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method)

The race condition occurs in the method threadFinished in the class NotificationThreads. The operation threadsRunning-- ist not atomic and this can lead to the race condition between counting down and compare it with 0.

--> http://www.informit.com/guides/content.aspx?g=java&seqNum=248

So our solution was to define the method as synchronized:

protected synchronized void threadFinished(NotificationThread notificationThread) { threadsRunning--; if (threadsRunning == 0) { if (listener != null) listener.eventAllThreadsFinished(this); try { synchronized (finishPoint) { finishPoint.notifyAll(); } } catch (Exception e) { e.printStackTrace(); } } }

Maybe you could fix this issue in a further release? Am i the first one who reported this error or did you already had some thread issues?

regards angela

Original issue: http://code.google.com/p/javapns/issues/detail?id=98

mwkirk commented 11 years ago

This issue is a duplicate of #92