/* * Copyright (c) 2012 GigaSpaces Technologies Ltd. All rights reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.openspaces.bigdata.feeder; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.annotation.Resource; import org.openspaces.core.GigaSpace; import org.springframework.beans.factory.annotation.Value; import org.springframework.dao.DataAccessException; import org.springframework.social.twitter.api.Tweet; import org.springframework.social.twitter.api.impl.TwitterTemplate; import org.springframework.stereotype.Component; import com.gigaspaces.document.DocumentProperties; import com.gigaspaces.document.SpaceDocument; /** * A bean that schedules Runnable tasks periodically * * @author Dotan Horovits */ public class TaskScheduler { private static final Logger log = Logger.getLogger(TaskScheduler.class.getName()); @Resource private Runnable task; private int delayInMs = 1000; public void setDelayInMs(int delayInMs) { this.delayInMs = delayInMs; } private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); public static void main(String[] args) { new TaskScheduler().execute(); } @PostConstruct public void execute() { executorService.scheduleWithFixedDelay(task, delayInMs, delayInMs, TimeUnit.MILLISECONDS); } @PreDestroy public void destroy() { executorService.shutdown(); } }