Raudius / Pushraven

A simple Java library to interface with Firebase Cloud Messaging (FCM) API. Pushraven allows you to push notifications to clients in very few lines of code.
MIT License
78 stars 34 forks source link

Efficient usage in multi-thread application #2

Closed rezaep closed 8 years ago

rezaep commented 8 years ago

Hi, I want to use this library in a web application ( in server side ) which is multi-thread. I need to send multiple notification in same time and i want to reduce creating new objects. How should i use Pushraven object in this case? Pushraven object is not singleton, am i right?

Raudius commented 8 years ago

That would depend on how the notifications to be sent differ between threads. Are there shared attributes between all your notifications? I am curious how I can add to the implementation to help with multi-threadded opperations.

You are right, Pushraven is not a singleton. Pushraven as it is currently simply holds notification parameters from the FCM protocol, which are then (upon raven.push()) turned into JSON and sent via HTTP to the FCM Web API. You can make as many Pushraven objects as you wish.

I programmed Pushraven for a small project of mine, and have not done much with it since, without knowing the details of your application I cannot give you much of an answer. If you have any feedback as to how to make it more efficient in multi-threadded scenarios I am interested in hearing it.

rezaep commented 8 years ago

Thanks for reply and your great library. Yes it is small library but it save a lot of time from me and i sent my first push in less than 5 minutes! Holding notification parameters are not much important for me. Making the class Singleton help to decrease object instantiation to only only one. Even it can be a class with static methods.

Raudius commented 8 years ago

Done!

I've updated Pushraven with your suggestion of making Pushraven a singleton. I must admit it makes more sense this way. Even when you are not multithreadding.

Notification objects are still instantiatable so it doesn't completely break any old implementations. But if you use the Pushraven.notification you wont need to instantiate more than just the one.

rezaep commented 8 years ago

Thanks. Yes of course it's so much better now. I thinks you should update example code in Main.java class with new changes. I close the issue ;)