List of usage examples for java.util.concurrent Executors newSingleThreadScheduledExecutor
public static ScheduledExecutorService newSingleThreadScheduledExecutor()
From source file:org.wso2.carbon.repository.core.handlers.builtin.OperationStatisticsHandler.java
private static synchronized void initializeStatisticsLogging() { if (executor != null) { return;//w ww . j a v a 2s .c o m } records = new HashMap<Method, Long>(); executor = Executors.newCachedThreadPool(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { executor.shutdownNow(); } }); for (Method method : new Method[] { Method.GET, Method.PUT, Method.IMPORT, Method.MOVE, Method.COPY, Method.RENAME, Method.DELETE, Method.ADD_ASSOCIATION, Method.REMOVE_ASSOCIATION, Method.GET_ASSOCIATIONS, Method.GET_ALL_ASSOCIATIONS, Method.EXECUTE_QUERY, Method.RESOURCE_EXISTS, Method.DUMP, Method.RESTORE }) { records.put(method, 0l); } final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { scheduler.shutdownNow(); } }); Runnable runnable = new Runnable() { public void run() { if (records == null) { log.error("Unable to store operation statistics."); } else { synchronized (this) { statsLog.debug("Total Number of get calls : " + records.get(Method.GET)); statsLog.debug("Total Number of put calls : " + records.get(Method.PUT)); statsLog.debug("Total Number of import calls : " + records.get(Method.IMPORT)); statsLog.debug("Total Number of move calls : " + records.get(Method.MOVE)); statsLog.debug("Total Number of copy calls : " + records.get(Method.COPY)); statsLog.debug("Total Number of rename calls : " + records.get(Method.RENAME)); statsLog.debug("Total Number of delete calls : " + records.get(Method.DELETE)); statsLog.debug("Total Number of addAssociation calls : " + records.get(Method.ADD_ASSOCIATION)); statsLog.debug("Total Number of removeAssociation calls : " + records.get(Method.REMOVE_ASSOCIATION)); statsLog.debug("Total Number of getAssociations calls : " + records.get(Method.GET_ASSOCIATIONS)); statsLog.debug("Total Number of getAllAssociations calls : " + records.get(Method.GET_ALL_ASSOCIATIONS)); statsLog.debug( "Total Number of executeQuery calls : " + records.get(Method.EXECUTE_QUERY)); statsLog.debug("Total Number of resourceExists calls : " + records.get(Method.RESOURCE_EXISTS)); statsLog.debug("Total Number of dump calls : " + records.get(Method.DUMP)); statsLog.debug("Total Number of restore calls : " + records.get(Method.RESTORE)); } } } }; scheduler.scheduleAtFixedRate(runnable, 60, 60, TimeUnit.SECONDS); }
From source file:net.sourceforge.subsonic.ajax.ChatService.java
/** * Invoked by Spring./*w w w. j a v a2s . c o m*/ */ public void init() { // Delete old messages every hour. ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); Runnable runnable = new Runnable() { public void run() { removeOldMessages(); } }; executor.scheduleWithFixedDelay(runnable, 0L, 3600L, TimeUnit.SECONDS); }
From source file:org.apache.ode.jbi.OdeConsumerAsync.java
OdeConsumerAsync(OdeContext ode) { super(ode);//w ww .ja v a2s . c o m _executor = Executors.newSingleThreadScheduledExecutor(); _executor.scheduleWithFixedDelay(new MEXReaper(), _responseTimeout, _responseTimeout / 10, TimeUnit.MILLISECONDS); }
From source file:org.wso2.carbon.registry.core.jdbc.handlers.builtin.OperationStatisticsHandler.java
private static synchronized void initializeStatisticsLogging() { if (executor != null) { return;/* w w w .ja va 2 s .c o m*/ } records = new HashMap<String, Long>(); executor = Executors.newCachedThreadPool(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { executor.shutdownNow(); } }); for (String s : new String[] { Filter.GET, Filter.PUT, Filter.IMPORT, Filter.MOVE, Filter.COPY, Filter.RENAME, Filter.DELETE, Filter.ADD_ASSOCIATION, Filter.REMOVE_ASSOCIATION, Filter.GET_ASSOCIATIONS, Filter.GET_ALL_ASSOCIATIONS, Filter.EXECUTE_QUERY, Filter.RESOURCE_EXISTS, Filter.DUMP, Filter.RESTORE }) { records.put(s, 0l); } final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { scheduler.shutdownNow(); } }); Runnable runnable = new Runnable() { public void run() { if (records == null) { log.error("Unable to store operation statistics."); } else { synchronized (this) { statsLog.debug("Total Number of get calls : " + records.get(Filter.GET)); statsLog.debug("Total Number of put calls : " + records.get(Filter.PUT)); statsLog.debug("Total Number of import calls : " + records.get(Filter.IMPORT)); statsLog.debug("Total Number of move calls : " + records.get(Filter.MOVE)); statsLog.debug("Total Number of copy calls : " + records.get(Filter.COPY)); statsLog.debug("Total Number of rename calls : " + records.get(Filter.RENAME)); statsLog.debug("Total Number of delete calls : " + records.get(Filter.DELETE)); statsLog.debug("Total Number of addAssociation calls : " + records.get(Filter.ADD_ASSOCIATION)); statsLog.debug("Total Number of removeAssociation calls : " + records.get(Filter.REMOVE_ASSOCIATION)); statsLog.debug("Total Number of getAssociations calls : " + records.get(Filter.GET_ASSOCIATIONS)); statsLog.debug("Total Number of getAllAssociations calls : " + records.get(Filter.GET_ALL_ASSOCIATIONS)); statsLog.debug( "Total Number of executeQuery calls : " + records.get(Filter.EXECUTE_QUERY)); statsLog.debug("Total Number of resourceExists calls : " + records.get(Filter.RESOURCE_EXISTS)); statsLog.debug("Total Number of dump calls : " + records.get(Filter.DUMP)); statsLog.debug("Total Number of restore calls : " + records.get(Filter.RESTORE)); } } } }; scheduler.scheduleAtFixedRate(runnable, 60, 60, TimeUnit.SECONDS); }
From source file:org.spring.data.gemfire.app.main.ClientCacheApp.java
@Override public void run() { final ClientCache clientCache = getBean(DEFAULT_GEMFIRE_CACHE_BEAN_NAME, ClientCache.class); assert clientCache != null : String.format( "The GemFire ClientCache was not properly configured and initialized in the Spring context!"); System.out.printf("Current GemFire Cache Servers are...%n"); for (InetSocketAddress address : clientCache.getDefaultPool().getServers()) { System.out.printf("%1$s%n", address); }// www . j av a2 s . co m System.out.printf("Current GemFire Client Cache Regions are...%n"); for (Region region : clientCache.rootRegions()) { System.out.printf("%1$s%n", region.getFullPath()); } if (!clientCache.rootRegions().isEmpty()) { Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() { @Override public void run() { for (Region<?, ?> region : clientCache.rootRegions()) { System.out.printf("*** Region %1$s ***%n", region.getFullPath()); for (Entry entry : region.entrySet()) { System.out.printf("%1$s = %2$s%n", entry.getKey(), entry.getValue()); } } } }, 5, 15, TimeUnit.SECONDS); } super.run(); }
From source file:com.kurtraschke.nyctrtproxy.ProxyModule.java
@Override protected void configure() { bind(HttpClientConnectionManager.class).toInstance(new PoolingHttpClientConnectionManager()); bind(ScheduledExecutorService.class).toInstance(Executors.newSingleThreadScheduledExecutor()); bind(CalendarServiceData.class).toProvider(CalendarServiceDataProvider.class).in(Scopes.SINGLETON); bind(GtfsRelationalDao.class).toProvider(GtfsRelationalDaoProvider.class).in(Scopes.SINGLETON); bind(ProxyDataListener.class).toInstance(new CloudwatchProxyDataListener()); bind(TripMatcher.class).toInstance(new LazyTripMatcher()); bind(TripUpdateProcessor.class).toInstance(new TripUpdateProcessor()); // for service alerts bind(SiriXmlSerializer.class).toInstance(new SiriXmlSerializer()); }
From source file:org.wso2.carbon.dataservices.google.tokengen.servlet.util.CodeHolder.java
/** * Private constructor to make the class singleton and start the cleanup process. *///from www . ja v a 2 s . c o m private CodeHolder() { if (GoogleTokenGenDSComponent.getHazelcastInstance() != null) { log.info("Creating Hazelcast map to store OAuth Codes"); authCodes = GoogleTokenGenDSComponent.getHazelcastInstance().getMap("GOOGLE_TOKENGEN_AUTHCODE_HOLDER"); } else { log.info("Creating simple HashMap to store OAuth Codes since clustering is not enabled"); authCodes = new HashMap<String, AuthCode>(2); } //retry interval 1 hour long interval = 1; //expiration time in milliseconds - default set to 30 mins. expirationTime = 1000 * 60 * 30; globalExecutorService = Executors.newSingleThreadScheduledExecutor(); globalExecutorService.scheduleAtFixedRate(this, interval, interval, TimeUnit.HOURS); }
From source file:net.ymate.platform.module.search.support.IndexHelper.java
public IndexHelper(ISearchConfig config) { __isBuildWorkingSet = Collections.synchronizedSet(new HashSet<String>()); // ??30/*from www . jav a2s.c o m*/ long _period = config.getScheduledPeriod() * 1000L; if (_period <= 0) { _period = 30L * 1000L; } // commit?Reopen __scheduler = Executors.newSingleThreadScheduledExecutor(); // ?? __scheduler.scheduleAtFixedRate(new Runnable() { public void run() { if (__isWorking) { return; } __isWorking = true; try { _LOG.debug("Start Reopen Working..."); for (Map.Entry<String, IndexSearcher> entry : Searchs.__SEARCH_CACHES.entrySet()) { IndexReader _reader = entry.getValue().getIndexReader(); try { IndexReader _reOpenedReader = DirectoryReader.openIfChanged((DirectoryReader) _reader); if (_reOpenedReader != null && _reOpenedReader != _reader) { _reader.decRef(); Searchs.__SEARCH_CACHES.put(entry.getKey(), new IndexSearcher(_reOpenedReader)); } } catch (IOException ex) { _LOG.error("Reopen And DecRef IndexReader Error:", ex); } } } finally { _LOG.debug("End Reopen Working..."); __isWorking = false; } } }, _period, _period, TimeUnit.MILLISECONDS); }
From source file:org.deeplearning4j.util.DiskBasedQueue.java
public DiskBasedQueue(File dir) { this.dir = dir; if (!dir.exists() && dir.isDirectory()) { throw new IllegalArgumentException("Illegal queue: must be a directory"); }/*from ww w.j av a 2 s.c o m*/ if (!dir.exists()) dir.mkdirs(); if (dir.listFiles() != null && dir.listFiles().length > 1) try { FileUtils.deleteDirectory(dir); } catch (IOException e) { e.printStackTrace(); } dir.mkdir(); executorService = Executors.newSingleThreadScheduledExecutor(); executorService.execute(new Runnable() { @Override public void run() { while (running.get()) { while (!save.isEmpty()) addAndSave(save.poll()); try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }); }
From source file:fi.ilmoeuro.membertrack.holvi.HolviSynchronizer.java
public HolviSynchronizer(ObjectMapper objectMapper, Config config, SessionRunner<SessionTokenType> sessionRunner, UnitOfWork.Factory<SessionTokenType> uowFactory, Persons.Factory<SessionTokenType> personsFactory, Services.Factory<SessionTokenType> servicesFactory, Memberships.Factory<SessionTokenType> membershipsFactory) { this.config = config; this.holviPopulator = new HolviPopulator<SessionTokenType>(config.getPopulator(), sessionRunner, uowFactory, personsFactory, servicesFactory, objectMapper); this.deOverlapper = new MembershipPeriodDeOverlapper<SessionTokenType>(sessionRunner, uowFactory, membershipsFactory);/*from ww w. ja va 2 s . c o m*/ this.scheduler = Executors.newSingleThreadScheduledExecutor(); }