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)
waiting on <0x00002aaab3db2f18> (a java.lang.Object)
at java.lang.Object.wait(Object.java:485)
at javapns.notification.transmission.NotificationThreads.waitForAllThreads(NotificationThreads.java:344)
locked <0x00002aaab3db2f18> (a java.lang.Object)
at javapns.notification.transmission.NotificationThreads.waitForAllThreads(NotificationThreads.java:363)
at javapns.Push.payloads(Push.java:272)
at com.namics.wetteralarm.service.ApplePushNotificationServiceImpl.sendPushNotifications(ApplePushNotificationServiceImpl.java:87)
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.
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