javax.enterprise.concurrent.ManagedScheduledExecutorService Java Examples
The following examples show how to use
javax.enterprise.concurrent.ManagedScheduledExecutorService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManagedScheduledExecutorServiceTest.java From tomee with Apache License 2.0 | 7 votes |
@Test public void simpleSchedule() throws Exception { final ManagedScheduledExecutorService es = new ManagedScheduledExecutorServiceImplFactory().create(); final long start = System.currentTimeMillis(); final ScheduledFuture<Long> future = es.schedule(new Callable<Long>() { @Override public Long call() throws Exception { Thread.sleep(4000); return System.currentTimeMillis(); } }, 2, TimeUnit.SECONDS); assertEquals(6, TimeUnit.MILLISECONDS.toSeconds(future.get() - start), 1); }
Example #2
Source File: ConcurrentTaskScheduler.java From spring-analysis-note with MIT License | 6 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override @Nullable public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) { return (trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext())); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #3
Source File: ConcurrentTaskScheduler.java From java-technology-stack with MIT License | 6 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override @Nullable public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) { return (trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext())); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #4
Source File: ConcurrentTaskScheduler.java From audit4j-core with Apache License 2.0 | 6 votes |
/** * Schedule. * * @param task * the task * @param trigger * the trigger * @return the scheduled future */ public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override public Date getNextRunTime(LastExecution le, Date taskScheduledTime) { return trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le .getRunStart(), le.getRunEnd()) : new SimpleTriggerContext()); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #5
Source File: CustomInjectionTest.java From tomee with Apache License 2.0 | 6 votes |
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses, final ManagedThreadFactory tf) { assertNotNull(es); assertNotNull(ses); assertNotNull(tf); assertThat(es, instanceOf(ManagedExecutorServiceImpl.class)); assertEquals(2, pool(es).getCorePoolSize()); assertEquals(10, pool(es).getMaximumPoolSize()); assertEquals(4, pool(es).getKeepAliveTime(TimeUnit.MINUTES)); assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class)); assertEquals(12, pool(ses).getCorePoolSize()); assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class)); assertEquals("custom-", Reflections.get(tf, "prefix")); }
Example #6
Source File: ConcurrentTaskScheduler.java From lams with GNU General Public License v2.0 | 5 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override public Date getNextRunTime(LastExecution le, Date taskScheduledTime) { return (trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext())); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #7
Source File: GameRound.java From liberty-bikes with Eclipse Public License 1.0 | 5 votes |
private ManagedScheduledExecutorService executor() { try { return InitialContext.doLookup("java:comp/DefaultManagedScheduledExecutorService"); } catch (NamingException e) { log("Unable to obtain ManagedScheduledExecutorService"); e.printStackTrace(); return null; } }
Example #8
Source File: ConcurrentTaskScheduler.java From spring4-understanding with Apache License 2.0 | 5 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override public Date getNextRunTime(LastExecution le, Date taskScheduledTime) { return trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext()); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #9
Source File: BuiltInEnvironmentEntries.java From tomee with Apache License 2.0 | 5 votes |
private void add(final JndiConsumer jndi, final DeploymentModule module, final DeploymentModule app, final boolean defaults) { // Standard names add(jndi.getEnvEntryMap(), new EnvEntry().name("java:module/ModuleName").value(module.getModuleId()).type(String.class)); add(jndi.getEnvEntryMap(), new EnvEntry().name("java:app/AppName").value(app.getModuleId()).type(String.class)); // Standard References to built-in objects add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/BeanManager").type(BeanManager.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/Validator").type(Validator.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/ValidatorFactory").type(ValidatorFactory.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionManager").type(TransactionManager.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionSynchronizationRegistry").type(TransactionSynchronizationRegistry.class)); if (defaults) { add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedExecutorService").type(ManagedExecutorService.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedScheduledExecutorService").type(ManagedScheduledExecutorService.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedThreadFactory").type(ManagedThreadFactory.class)); add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultContextService").type(ContextService.class)); try { final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); contextClassLoader.loadClass("org.apache.activemq.ActiveMQSslConnectionFactory"); final ResourceEnvRef ref = new ResourceEnvRef().name("java:comp/DefaultJMSConnectionFactory") .type(contextClassLoader.loadClass("javax.jms.ConnectionFactory")); add(jndi.getResourceEnvRefMap(), ref); } catch (final ClassNotFoundException | NoClassDefFoundError notThere) { // no-op } } // OpenEJB specific feature add(jndi.getEnvEntryMap(), new EnvEntry().name("java:comp/ComponentName").value(jndi.getJndiConsumerName()).type(String.class)); }
Example #10
Source File: InjectionTest.java From tomee with Apache License 2.0 | 5 votes |
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses, final ContextService ces, final ManagedThreadFactory tf) { assertNotNull(es); assertNotNull(ses); assertNotNull(ces); assertNotNull(tf); assertThat(es, instanceOf(ManagedExecutorServiceImpl.class)); assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class)); assertThat(ces, instanceOf(ContextServiceImpl.class)); assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class)); }