List of usage examples for java.util.concurrent Executors newScheduledThreadPool
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize)
From source file:bjerne.gallery.service.impl.VideoBatchConversionJob.java
@PostConstruct public void startBatchService() { executor = Executors.newScheduledThreadPool(1); Runnable batchJob = () -> runBatchJob(); executor.scheduleAtFixedRate(batchJob, initialDelaySeconds, waitPeriodSeconds, TimeUnit.SECONDS); }
From source file:ai.grakn.engine.tasks.manager.StandaloneTaskManager.java
public StandaloneTaskManager(EngineID engineId) { this.engineID = engineId; instantiatedTasks = new ConcurrentHashMap<>(); stateStorage = new TaskStateInMemoryStore(); stateUpdateLock = new ReentrantLock(); ConfigProperties properties = ConfigProperties.getInstance(); schedulingService = Executors.newScheduledThreadPool(1); executorService = Executors.newFixedThreadPool(properties.getAvailableThreads()); }
From source file:eu.vital.vitalcep.collector.Collector.java
private Collector() throws IOException { ConfigReader configReader = ConfigReader.getInstance(); mongoURL = configReader.get(ConfigReader.MONGO_URL); mongoDB = configReader.get(ConfigReader.MONGO_DB); getCollectorList();/*from ww w. j a v a 2 s . c om*/ ScheduledExecutorService exec = Executors.newScheduledThreadPool(2); Runnable collectoRunnable; collectoRunnable = new Runnable() { @Override public void run() { if (sensors.length() > 0) { mongo = new MongoClient(new MongoClientURI(mongoURL)); db = mongo.getDatabase(mongoDB); } Date NOW = new Date(); String nowString = getXSDDateTime(NOW); for (int i = 0; i < sensors.length(); i++) { try { String cookie = getListenerCredentials(i); JSONArray aData = new JSONArray(); String type = sensors.getJSONObject(i).getString("cepType"); if (type.equals("CONTINUOUS")) { try { DMSListener oDMS = new DMSListener(cookie); aData = oDMS.getObservations(sensors.getJSONObject(i).getJSONArray("sources"), sensors.getJSONObject(i).getJSONArray("properties"), sensors.getJSONObject(i).getString("lastRequest")); } catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) { java.util.logging.Logger.getLogger(Collector.class.getName()).log(Level.SEVERE, null, ex); } if (aData.length() > 0) { sendData2CEP(aData, i); } } else { try { JSONObject sensor = new JSONObject(); sensor = sensors.getJSONObject(i); JSONArray requests = new JSONArray(); requests = sensor.getJSONArray("requests"); PPIListener oPPI = new PPIListener(cookie); aData = oPPI.getObservations(requests, sensor.getString("lastRequest")); if (aData.length() > 0) { sendData2CEP(aData, i); } } catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) { java.util.logging.Logger.getLogger(Collector.class.getName()).log(Level.SEVERE, null, ex); } } sensors.getJSONObject(i).put("lastRequest", nowString); if (mongo == null) mongo = new MongoClient(new MongoClientURI(mongoURL)); if (db == null) db = mongo.getDatabase(mongoDB); Bson filter = Filters.eq("_id", new ObjectId(sensors.getJSONObject(i).getString("id"))); Bson update = new Document("$set", new Document("lastRequest", nowString)); UpdateOptions options = new UpdateOptions().upsert(false); UpdateResult updateDoc = db.getCollection("cepinstances").updateOne(filter, update, options); } catch (GeneralSecurityException | IOException | ParseException ex) { java.util.logging.Logger.getLogger(Collector.class.getName()).log(Level.SEVERE, null, ex); } finally { if (db != null) db = null; if (mongo != null) { mongo.close(); mongo = null; } } } if (db != null) db = null; if (mongo != null) { mongo.close(); mongo = null; } } private void sendData2CEP(JSONArray aData, int i) throws JSONException, ParseException { Decoder decoder = new Decoder(); ArrayList<String> simpleEventAL = decoder.JsonldArray2DolceInput(aData); MqttAllInOne oMqtt = new MqttAllInOne(); TMessageProc MsgProcc = new TMessageProc(); //TODO: check the client name. see from cep instances and what happen when if the topic exist String clientName = "collector_" + RandomStringUtils.randomAlphanumeric(4); oMqtt.sendMsg(MsgProcc, clientName, simpleEventAL, sensors.getJSONObject(i).getString("mqin"), sensors.getJSONObject(i).getString("mqout"), true); } private String getListenerCredentials(int i) throws IOException, GeneralSecurityException, JSONException { StringBuilder ck = new StringBuilder(); Security slogin = new Security(); JSONObject credentials = new JSONObject(); // Boolean token = slogin.login(sensors.getJSONArray(i) // .getJSONObject(0) // .getString("username") // ,decrypt(sensors.getJSONArray(i) // .getJSONObject(0) // .getString("password")),false,ck); Boolean token = slogin.login("elisa", "elisotas1", false, ck); if (!token) { //throw new } String cookie = ck.toString(); return cookie; } }; exec.scheduleAtFixedRate(collectoRunnable, 0, 10, TimeUnit.SECONDS); }
From source file:org.openmrs.module.xdsbrepository.XDSbRepositoryInterfaceActivator.java
/** * @see ModuleActivator#started()// www . ja v a 2 s. co m */ public void started() { XDSAudit.setAuditLogger(Context.getService(AtnaAuditService.class).getLogger()); XDSAudit.logApplicationActivity(AtnaConfiguration.getInstance().getDeviceName(), EventTypeCode.ApplicationStart, true); log.info("XDSb Repository Interface Module started"); AdministrationService as = Context.getAdministrationService(); boolean async = Boolean .parseBoolean(as.getGlobalProperty(XDSbServiceConstants.XDS_REPOSITORY_DISCRETE_HANDLER_ASYNC)); int pollPeriod = Integer.parseInt(Context.getAdministrationService() .getGlobalProperty(XDSbServiceConstants.XDS_REPOSITORY_DISCRETE_HANDLER_ASYNC_POLL_PERIOD, "100")); if (async) { Integer maxTasks = Integer.parseInt( as.getGlobalProperty(XDSbServiceConstants.XDS_REPOSITORY_DISCRETE_HANDLER_ASYNC_MAX_TASKS)); ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(maxTasks); // for each thread schedule a recurring task for (int i = 0; i < maxTasks; i++) { scheduledExecutorService.scheduleWithFixedDelay(new DiscreteDataProcessorTask(), pollPeriod, pollPeriod, TimeUnit.MILLISECONDS); } } }
From source file:ai.grakn.engine.backgroundtasks.standalone.StandaloneTaskManager.java
private StandaloneTaskManager() { instantiatedTasks = new ConcurrentHashMap<>(); stateStorage = InMemoryStateStorage.getInstance(); stateUpdateLock = new ReentrantLock(); ConfigProperties properties = ConfigProperties.getInstance(); schedulingService = Executors.newScheduledThreadPool(1); executorService = Executors.newFixedThreadPool(properties.getAvailableThreads()); }
From source file:org.obp.local.LocalObpInstance.java
@PostConstruct public void init() { attachInstrument(nmeaGpsReceiver);//from w w w . ja v a 2 s . c o m attachInstrument(nmeaWindVane); attachInstrument(defaultDataInstrument);//new DefaultDataInstrument("/defaults.properties")); attachInstrument(new SystemTimeInstrument()); attachExplorer(new DummyRadar()); scanner = Executors.newScheduledThreadPool(1); randomizeIntendedRoute(); maritimeCloudAgent.connect(createPositionReader(), intendedRouteRef, this); if (maritimeCloudAgent.isConnected()) { if (config.isRemoteWeatherScanner()) { attachInstrument(new RemoteWeatherInstrument(scanner, maritimeCloudAgent)); } else { maritimeCloudAgent.registerService(new WeatherService(this)); } } //initRemoteBodies(); logger.info("init local OBP instance:\n\n" + toString() + "\n"); }
From source file:org.apache.hama.bsp.BSPTask.java
public BSPTask() { this.pingService = Executors.newScheduledThreadPool(1); }
From source file:org.openspaces.example.data.feeder.JMSDataFeeder.java
@PostConstruct public void construct() { System.out.println("--- STARTING FEEDER WITH CYCLE [" + defaultDelay + "]"); if (instanceId != null) { // have a range of ids based on the instance id of the processing unit startIdFrom = instanceId * 100000000; }/*ww w . j ava 2 s .co m*/ executorService = Executors.newScheduledThreadPool(1); dataFeederTask = new JMSDataFeederTask(); sf = executorService.scheduleAtFixedRate(dataFeederTask, defaultDelay, defaultDelay, TimeUnit.MILLISECONDS); }
From source file:org.verwandlung.voj.judger.application.ApplicationBootstrap.java
/** * ?Web?.//from ww w. j a v a2 s . c o m * ?Web???Keep-Alive?. */ private void setupHeartBeat() { final int INITIAL_DELAY = 0; final int PERIOD = 25; ApplicationHeartbeat heartbeat = applicationContext.getBean(ApplicationHeartbeat.class); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(heartbeat, INITIAL_DELAY, PERIOD, TimeUnit.MINUTES); }