List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor()
From source file:org.apache.hedwig.server.netty.TestPubSubServer.java
@Test(timeout = 60000) public void testUncaughtExceptionInZKThread() throws Exception { SynchronousQueue<Throwable> queue = new SynchronousQueue<Throwable>(); RecordingUncaughtExceptionHandler uncaughtExceptionHandler = new RecordingUncaughtExceptionHandler(queue); final int port = PortManager.nextFreePort(); final String hostPort = "127.0.0.1:" + PortManager.nextFreePort(); PubSubServer server = startServer(uncaughtExceptionHandler, port, new TopicManagerInstantiator() { @Override/*w w w . j a v a2 s . c o m*/ public TopicManager instantiateTopicManager() throws IOException { return new AbstractTopicManager(new ServerConfiguration(), Executors.newSingleThreadScheduledExecutor()) { @Override protected void realGetOwner(ByteString topic, boolean shouldClaim, Callback<HedwigSocketAddress> cb, Object ctx) { ZooKeeper zookeeper; try { zookeeper = new ZooKeeper(hostPort, 60000, new Watcher() { @Override public void process(WatchedEvent event) { // TODO Auto-generated method stub } }); } catch (IOException e) { throw new RuntimeException(e); } zookeeper.getData("/fake", false, new SafeAsyncZKCallback.DataCallback() { @Override public void safeProcessResult(int rc, String path, Object ctx, byte[] data, org.apache.zookeeper.data.Stat stat) { throw new RuntimeException("This should go to the uncaught exception handler"); } }, null); } @Override protected void postReleaseCleanup(ByteString topic, Callback<Void> cb, Object ctx) { } }; } }); runPublishRequest(port); assertEquals(RuntimeException.class, queue.take().getClass()); server.shutdown(); }
From source file:org.exoplatform.platform.common.software.register.UnlockService.java
public void start() { if (!new File(Utils.HOME_CONFIG_FILE_LOCATION).exists()) { if (checkLicenceInJcr()) return; String rdate = UnlockService.computeRemindDateFromTodayBase64(); productCode = generateProductCode(); Utils.writeToFile(Utils.PRODUCT_KEY, "", Utils.HOME_CONFIG_FILE_LOCATION); Utils.writeToFile(Utils.PRODUCT_CODE, productCode, Utils.HOME_CONFIG_FILE_LOCATION); Utils.writeToFile(Utils.REMIND_DATE, rdate, Utils.HOME_CONFIG_FILE_LOCATION); }//from ww w.j a v a 2 s . c o m productCode = Utils.readFromFile(Utils.PRODUCT_CODE, Utils.HOME_CONFIG_FILE_LOCATION); String unlockKey = Utils.readFromFile(Utils.PRODUCT_KEY, Utils.HOME_CONFIG_FILE_LOCATION); if ((unlockKey != null) && (!unlockKey.equals(""))) { int period = decodeKey(productCode, unlockKey); if (period == -1) { try { PingBackServlet.writePingBackFormDisplayed(true); } catch (MissingProductInformationException e) { LOG.error("Product Information not found ", e.getLocalizedMessage()); } outdated = false; isUnlocked = true; showTermsandConditions = false; return; } } if (checkLicenceInJcr()) return; //Read if extended String isExtendedString = Utils.readFromFile(Utils.IS_EXTENDED, Utils.HOME_CONFIG_FILE_LOCATION); if (isExtendedString != null && !isExtendedString.isEmpty()) { isExtendedString = new String(Base64.decodeBase64(isExtendedString.getBytes())); isUnlocked = Boolean.parseBoolean(isExtendedString); } // Read: Remind date String remindDateString = Utils.readFromFile(Utils.REMIND_DATE, Utils.HOME_CONFIG_FILE_LOCATION); try { remindDate = Utils.parseDateBase64(remindDateString); } catch (Exception e) { //Added to not have NPE if user played with licence.xml given by sales //or user play with remindDate param in licence.xml remindDate = Calendar.getInstance(); remindDate.set(Calendar.HOUR, 23); remindDate.set(Calendar.MINUTE, 59); remindDate.set(Calendar.SECOND, 59); remindDate.set(Calendar.MILLISECOND, 59); ERROR = "your license file is incorrect, please contact our support to fix the problem"; } computeUnlockedInformation(); // Compute delay period every day executor = Executors.newSingleThreadScheduledExecutor(); executor.scheduleWithFixedDelay(new Runnable() { public void run() { computeUnlockedInformation(); if (outdated && isUnlocked) { isUnlocked = false; Utils.writeToFile(Utils.IS_EXTENDED, new String(Base64.encodeBase64("false".getBytes())), Utils.HOME_CONFIG_FILE_LOCATION); } } }, 1, 1, TimeUnit.MINUTES); }
From source file:edu.usf.cutr.gtfs_realtime.bullrunner.GtfsRealtimeProviderImpl.java
@PostConstruct public void start() { routeVehicleStartTimeMap = new BiHashMap<String, String, StartTimes>(); try {// ww w . j a v a2s . co m //_providerConfig .setUrl(new URL( "http://usfbullrunner.com/region/0/routes")); _providerConfig.generatesRouteMap(new URL("http://usfbullrunner.com/region/0/routes")); _providerConfig.generateTripMap(); _providerConfig.generateServiceMap(); _providerConfig.extractSeqId(); _providerConfig.extractStartTime(); } catch (Exception ex) { _log.warn("Error in retriving confirmation data!", ex); } _log.info("starting GTFS-realtime service"); _executor = Executors.newSingleThreadScheduledExecutor(); _executor.scheduleAtFixedRate(new VehiclesRefreshTask(), 0, _refreshInterval, TimeUnit.SECONDS); }
From source file:com.taobao.common.store.journal.JournalStore.java
/** * /*from w ww. j ava 2 s. c o m*/ * * @param path * @param name * @param force * @throws IOException */ public JournalStore(final String path, final String name, final IndexMap indices, final boolean force, final boolean enableIndexLRU, final boolean enabledDataFileCheck) throws IOException { Util.registMBean(this, name); this.path = path; this.name = name; this.force = force; if (indices == null) { if (enableIndexLRU) { final long maxMemory = Runtime.getRuntime().maxMemory(); // 1/40 final int capacity = (int) (maxMemory / 40 / 60); this.indices = new LRUIndexMap(capacity, this.getPath() + File.separator + name + "_indexCache", enableIndexLRU); } else { this.indices = new ConcurrentIndexMap(); } } else { this.indices = indices; } this.dataFileAppender = new DataFileAppender(this); this.initLoad(); // if (null == this.dataFile || null == this.logFile) { this.newDataFile(); } // Store4j. if (enabledDataFileCheck) { this.scheduledPool = Executors.newSingleThreadScheduledExecutor(); this.scheduledPool.scheduleAtFixedRate(new DataFileCheckThread(), this.calcDelay(), HALF_DAY, TimeUnit.MILLISECONDS); log.warn(""); } // ,,. Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { JournalStore.this.close(); } catch (final IOException e) { log.error("close error", e); } } }); }
From source file:org.apache.hadoop.hdfs.server.datanode.OfferService.java
public void run() { if (!shouldRun()) return;/*ww w . ja v a 2 s .co m*/ KeepAliveHeartbeater keepAliveTask = new KeepAliveHeartbeater(namenode, nsRegistration, this.servicePair); keepAliveSender = Executors.newSingleThreadScheduledExecutor(); keepAliveRun = keepAliveSender.scheduleAtFixedRate(keepAliveTask, 0, anode.heartBeatInterval, TimeUnit.MILLISECONDS); while (shouldRun()) { try { if (isPrimaryService()) { servicePair.setPrimaryOfferService(this); } offerService(); } catch (Exception e) { LOG.error("OfferService encountered exception", e); } } stop(); }
From source file:app.screen.MyActivity.java
/** create a repeating executor that displays debug messages after interacting with service */ private void _scheduleRepeatingTask() { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); executor.scheduleAtFixedRate(new Runnable() { public void run() { try { StringBuilder sb = new StringBuilder(); sb.append("ScheduledExecutorRunning - ").append(new Date().toString()); AndroidUtils.log(IconPaths.MyApp, sb.toString()); } catch (Exception e) { }/* www . j av a 2 s . c om*/ } }, 0, MyActivityRepeatDelay_ms, TimeUnit.MILLISECONDS); lifecycleHelper.addResource(executor); }
From source file:com.scooter1556.sms.android.fragment.AudioPlayerFragment.java
@Override public void onResume() { super.onResume(); // Player control update thread executorService = Executors.newSingleThreadScheduledExecutor(); final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override/*from w ww .j a v a2 s. co m*/ public void run() { handler.post(new Runnable() { @Override public void run() { updateProgressBar(); } }); } }; executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); // Update player controls updatePlayerControls(); // Set current media info updateMediaInfo(); }
From source file:com.app.server.util.FarmWarFileTransfer.java
public void start() { try {/* ww w. j av a 2s . com*/ channel = new JChannel(); channel.setReceiver(this); /*ProtocolStack stack=new ProtocolStack(); // 2 channel.setProtocolStack(stack); stack.addProtocol(new UDP().setValue("bind_addr", InetAddress.getByName("0.0.0.0"))); //stack.addProtocol(new NAKACK()); stack.init();*/ channel.connect(serverConfig.getClustergroup()); address = channel.getAddress().toString(); channel.getState(null, 10000); // channel.close(); } catch (Exception ex) { log.info("Could not able to create jgroups Channel for the cluster group " + serverConfig.getClustergroup(), ex); } exec = Executors.newSingleThreadScheduledExecutor(); FarmWarDirWatcher task = new FarmWarDirWatcher(serverConfig.getFarmWarDir(), this); exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS); serviceList.add(objName.getCanonicalName()); }
From source file:at.wada811.android.library.demos.concurrent.ExecutorActivity.java
/** * {@link ScheduledExecutorService#schedule(Runnable, long, TimeUnit)} ????? * /*w ww .ja v a2 s . c o m*/ * <p> * ??????????? * </p> */ public void newSingleThreadScheduledExecutorTest() { LogUtils.d(); ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.schedule(new ExecutorRunnable("A", 1), 8, TimeUnit.SECONDS); executorService.schedule(new ExecutorRunnable("B", 1), 4, TimeUnit.SECONDS); executorService.schedule(new ExecutorRunnable("C", 1), 0, TimeUnit.SECONDS); executorService.schedule(new ExecutorRunnable("D", 1), 12, TimeUnit.SECONDS); }
From source file:org.jsecurity.realm.text.PropertiesRealm.java
protected void startReloadThread() { if (this.reloadIntervalSeconds > 0) { this.scheduler = Executors.newSingleThreadScheduledExecutor(); ((ScheduledExecutorService) this.scheduler).scheduleAtFixedRate(this, reloadIntervalSeconds, reloadIntervalSeconds, TimeUnit.SECONDS); }//w ww. j av a 2 s . c o m }