Thursday, September 24, 2015

Java PNS Multi threading - sending to multiple devices

Apparently, sending to multiple devices is quite easy in and the code is like below. 

When tried this, below two observations i had

1. With the threading, code that is compiled in MAC when moved to Windows, it appears that the message is not sent properly. Probably we need to compile on Windows Java compiler itself? 
2. It appeared that if no multi threading, the whole program holds and continue after only the message is sent.
3. Without multi threading if application is trying to create a new thread and send the message, 

public void send (List devices, Object keystore, String password, boolean production) {
    
    /* Prepare a simple payload to push */
    PushNotificationPayload payload = PushNotificationPayload.alert("Hello World!");
    
    
    /* Decide how many threads you want to create and use */
    int threads = 30;
    
    
    /* Start threads, wait for them, and get a list of all pushed notifications */
    List notifications = Push.payload(payload, keystore, password, production, threads, devices);
    
    
}



References:
https://code.google.com/p/javapns/wiki/PushNotificationAdvanced

No comments:

Post a Comment