@Override public void afterPropertiesSet() throws Exception { String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); this.executor = threadPool; } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).start(); } this.scheduler.start(); }
@Override public void destroy() throws Exception { try { if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).stop(); } } catch (Throwable ex) { // ignore } try { if (this.scheduler != null) { this.scheduler.stop(); } } catch (Throwable ex) { // ignore } }
task = scheduler.schedule(() ->
/** * Get a scheduler. First try a common scheduler, failing that * create our own. * * @throws Exception when the scheduler cannot be started */ protected void findScheduler() throws Exception { if (_scheduler == null) { if (_sessionIdManager instanceof DefaultSessionIdManager) { //try and use a common scheduler, fallback to own _scheduler = ((DefaultSessionIdManager)_sessionIdManager).getServer().getBean(Scheduler.class); } if (_scheduler == null) { _scheduler = new ScheduledExecutorScheduler(); _ownScheduler = true; _scheduler.start(); if (LOG.isDebugEnabled()) LOG.debug("Using own scheduler for scavenging"); } else if (!_scheduler.isStarted()) throw new IllegalStateException("Shared scheduler not started"); } }
private void activate() { if (isRunning()) { Scheduler.Task t = scheduler.schedule(this, period, TimeUnit.MILLISECONDS); if (LOG.isDebugEnabled()) LOG.debug("Scheduled in {} ms sweep task {}", period, t); task.set(t); } else { if (LOG.isDebugEnabled()) LOG.debug("Skipping sweep task scheduling"); } }
/** * Start up the id manager. * * Makes necessary database tables and starts a Session * scavenger thread. */ @Override public void doStart() throws Exception { initializeDatabase(); prepareTables(); super.doStart(); if (LOG.isDebugEnabled()) LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec"); //try and use a common scheduler, fallback to own _scheduler =_server.getBean(Scheduler.class); if (_scheduler == null) { _scheduler = new ScheduledExecutorScheduler(); _ownScheduler = true; _scheduler.start(); } else if (!_scheduler.isStarted()) throw new IllegalStateException("Shared scheduler not started"); setScavengeInterval(getScavengeInterval()); }
/** * <p>Entry point to schedule tasks in CometD.</p> * <p>Subclasses may override and run the task in a {@link java.util.concurrent.Executor}, * rather than in the scheduler thread.</p> * * @param task the task to schedule * @param delay the delay, in milliseconds, to run the task * @return the task promise */ public Scheduler.Task schedule(Runnable task, long delay) { return _scheduler.schedule(task, delay, TimeUnit.MILLISECONDS); }
@Override public void destroy() throws Exception { try { if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).stop(); } } catch (Throwable ex) { // ignore } try { if (this.scheduler != null) { this.scheduler.stop(); } } catch (Throwable ex) { // ignore } }
@Override public void afterPropertiesSet() throws Exception { String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); this.executor = threadPool; } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).start(); } this.scheduler.start(); }
/** * Start up the id manager. * * Makes necessary database tables and starts a Session * scavenger thread. */ @Override public void doStart() throws Exception { initializeDatabase(); prepareTables(); super.doStart(); if (LOG.isDebugEnabled()) LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec"); //try and use a common scheduler, fallback to own _scheduler =_server.getBean(Scheduler.class); if (_scheduler == null) { _scheduler = new ScheduledExecutorScheduler(); _ownScheduler = true; _scheduler.start(); } else if (!_scheduler.isStarted()) throw new IllegalStateException("Shared scheduler not started"); setScavengeInterval(getScavengeInterval()); }
@Controller @RequestMapping("/schedule") class MyController { private Scheduler scheduler; @RequestMapping(method = RequestMethod.POST) public void scheduleSomething(Foo foo) { scheduler.schedule(foo); } }
@Override protected void doStop() throws Exception { if (_scheduler instanceof LRMScheduler) _scheduler.stop(); super.doStop(); }