public void run() throws Exception { for (Thread t : searcherThreads) { t.start(); } for (Thread t : writerThreads) { t.start(); } barrier1.await(); Refresher refresher = new Refresher(); scheduledExecutorService.scheduleWithFixedDelay( refresher, refreshSchedule.millis(), refreshSchedule.millis(), TimeUnit.MILLISECONDS); Flusher flusher = new Flusher(); scheduledExecutorService.scheduleWithFixedDelay( flusher, flushSchedule.millis(), flushSchedule.millis(), TimeUnit.MILLISECONDS); StopWatch stopWatch = new StopWatch(); stopWatch.start(); barrier2.await(); latch.await(); stopWatch.stop(); System.out.println("Summary"); System.out.println( " -- Readers [" + searcherThreads.length + "] with [" + searcherIterations + "] iterations"); System.out.println( " -- Writers [" + writerThreads.length + "] with [" + writerIterations + "] iterations"); System.out.println(" -- Took: " + stopWatch.totalTime()); System.out.println( " -- Refresh [" + refresher.id + "] took: " + refresher.stopWatch.totalTime()); System.out.println(" -- Flush [" + flusher.id + "] took: " + flusher.stopWatch.totalTime()); System.out.println(" -- Store size " + store.estimateSize()); scheduledExecutorService.shutdown(); engine.refresh(new Engine.Refresh(true)); stopWatch = new StopWatch(); stopWatch.start(); Engine.Searcher searcher = engine.searcher(); TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), idGenerator.get() + 1); stopWatch.stop(); System.out.println( " -- Indexed [" + idGenerator.get() + "] docs, found [" + topDocs.totalHits + "] hits, took " + stopWatch.totalTime()); searcher.release(); }
public JobLoggerDelegate(Config config) { JobLoggerFactory jobLoggerFactory = ExtensionLoader.getExtensionLoader(JobLoggerFactory.class).getAdaptiveExtension(); jobLogger = jobLoggerFactory.getJobLogger(config); lazyLog = config.getParameter(Constants.LAZY_JOB_LOGGER, false); if (lazyLog) { // 无界Queue memoryQueue = new LinkedBlockingQueue<JobLogPo>(); maxMemoryLogSize = config.getParameter(Constants.LAZY_JOB_LOGGER_MEM_SIZE, 1000); flushPeriod = config.getParameter(Constants.LAZY_JOB_LOGGER_CHECK_PERIOD, 3); executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("LazyJobLogger")); scheduledFuture = executor.scheduleWithFixedDelay( new Runnable() { @Override public void run() { try { if (flushing.compareAndSet(false, true)) { checkAndFlush(); } } catch (Throwable t) { LOGGER.error("CheckAndFlush log error", t); } } }, flushPeriod, flushPeriod, TimeUnit.SECONDS); } }
public RedisRegistry(AppContext appContext) { super(appContext); Config config = appContext.getConfig(); this.clusterName = config.getClusterName(); this.lock = new RedisLock("LTS_CLEAN_LOCK_KEY", config.getIdentity(), 2 * 60); // 锁两分钟过期 JedisPoolConfig redisConfig = new JedisPoolConfig(); // TODO 可以设置n多参数 String address = NodeRegistryUtils.getRealRegistryAddress(config.getRegistryAddress()); String cluster = config.getParameter("cluster", "failover"); if (!"failover".equals(cluster) && !"replicate".equals(cluster)) { throw new IllegalArgumentException( "Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate."); } replicate = "replicate".equals(cluster); this.reconnectPeriod = config.getParameter( ExtConfig.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD); String[] addrs = address.split(","); for (String addr : addrs) { int i = addr.indexOf(':'); String host = addr.substring(0, i); int port = Integer.parseInt(addr.substring(i + 1)); this.jedisPools.put(addr, new JedisPool(redisConfig, host, port, Constants.DEFAULT_TIMEOUT)); } this.expirePeriod = config.getParameter(ExtConfig.REDIS_SESSION_TIMEOUT, Constants.DEFAULT_SESSION_TIMEOUT); this.expireFuture = expireExecutor.scheduleWithFixedDelay( new Runnable() { public void run() { try { deferExpired(); // 延长过期时间 } catch (Throwable t) { // 防御性容错 LOGGER.error( "Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t); } } }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS); }
public AbstractPreLoader(final Application application) { if (start.compareAndSet(false, true)) { scheduledFuture = LOAD_EXECUTOR_SERVICE.scheduleWithFixedDelay( new Runnable() { @Override public void run() { for (String loadTaskTrackerNodeGroup : LOAD_SIGNAL) { BlockingQueue<JobPo> queue = JOB_MAP.get(loadTaskTrackerNodeGroup); if (queue.size() / step < factor) { // load List<JobPo> loads = load(loadTaskTrackerNodeGroup, curSequence * step); // 加入到内存中 if (CollectionUtils.isNotEmpty(loads)) { queue.addAll(loads); } } LOAD_SIGNAL.remove(loadTaskTrackerNodeGroup); } } }, 500, 500, TimeUnit.MILLISECONDS); } application .getEventCenter() .subscribe( new EventSubscriber( application.getConfig().getIdentity() + "_preLoader", new Observer() { @Override public void onObserved(EventInfo eventInfo) { setCurSequence(application); } }), EcTopic.NODE_ADD, EcTopic.NODE_REMOVE); setCurSequence(application); }
public ScheduledFuture<?> scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit) { return e.scheduleWithFixedDelay(command, initialDelay, delay, unit); }