mardi 28 juillet 2015

Sending Push Notifications for android app users located in different timezones

I am using spring mvc 4 for the backend. How can I solve this problem of sending Push Notifications for android app users located in different timezones, everyday at 8 am?

Here is my WebConfig.java

@Configuration
@EnableScheduling
@EnableWebMvc
@ComponentScan(basePackages="com.project")
public class WebConfig implements SchedulingConfigurer 
{    
    protected static final Logger slf4jLogger  =  Logger.getLogger(WebConfig.class.getName());
    private static final String cronExpression = "0 0 8 * * ?";

  static HashSet<String> userTimeZonesfromDB = null;
  String timezone = null; 

@Bean
public MobileNotifSchedulerBean schedulerbean()
{
    return new MobileNotifSchedulerBean();
}

CronTrigger cronTrigger() 
{
    CronTrigger crontrigger = null;
    if(timezone!=null)
    {
        crontrigger = new CronTrigger(cronExpression, TimeZone.getTimeZone(timezone));
        return crontrigger;
    }
    else
    {
        crontrigger = new CronTrigger(cronExpression);
        return crontrigger;
    }
}

@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) 
{
    userTimeZonesfromDB = FetchUserTimeZones.fetchUserTimeZone();
    if(userTimeZonesfromDB!=null)
    {
        for (String timeZones : userTimeZonesfromDB) 
        {
            timezone = timeZones;
            slf4jLogger.info("timeZones for CronTrigger.......: "+timezone);
            taskRegistrar.setScheduler(taskExecutor());
            taskRegistrar.addCronTask(new CronTask(schedulerbean(), cronTrigger()));
        }

    }
    else
    {
        taskRegistrar.setScheduler(taskExecutor());
        taskRegistrar.addCronTask(new CronTask(schedulerbean(), cronTrigger()));
    }
 }

 @Bean(destroyMethod="shutdown")
 public synchronized Executor taskExecutor() 
 {
    return Executors.newScheduledThreadPool(15);
 }
}

I noticed that android app users are getting multiple push notifications instead on only one notification and also in the wrong times but not at 8 am. I am not getting where I went wrong. Can you please guide me? TIA.

Aucun commentaire:

Enregistrer un commentaire