use of java.util.concurrent.ScheduledThreadPoolExecutor in project opennms by OpenNMS.
the class RuleSet method updateEngine.
public void updateEngine(DroolsCorrelationEngine engine) {
engine.setAssertBehaviour(getAssertBehaviour());
engine.setEventProcessingMode(getEventProcessingMode());
engine.setPersistState(getPersistState());
engine.setScheduler(new ScheduledThreadPoolExecutor(1));
engine.setInterestingEvents(getInterestingEvents());
engine.setRulesResources(getRuleResources(engine.getConfigContext()));
engine.setGlobals(getGlobals(engine.getConfigContext()));
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project opennms by OpenNMS.
the class JavaMailAckReaderIT method findAndProcessAcks.
@Ignore
@Test
public void findAndProcessAcks() throws InterruptedException {
AckReader reader = new DefaultAckReader();
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
reader.setAckProcessor(m_processor);
Future<?> f = executor.schedule(m_processor, 5, TimeUnit.SECONDS);
m_processor.setJmConfigDao(m_jmDao);
m_processor.setAckdConfigDao(createAckdConfigDao());
// Thread.sleep(20000);
while (!f.isDone()) {
Thread.sleep(10);
}
Assert.assertTrue(f.isDone());
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project android_frameworks_base by AOSPA.
the class FileOperationService method onCreate.
@Override
public void onCreate() {
// Allow tests to pre-set these with test doubles.
if (executor == null) {
executor = new ScheduledThreadPoolExecutor(POOL_SIZE);
}
if (jobFactory == null) {
jobFactory = Job.Factory.instance;
}
if (DEBUG)
Log.d(TAG, "Created.");
mPowerManager = getSystemService(PowerManager.class);
mNotificationManager = getSystemService(NotificationManager.class);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project ignite by apache.
the class AgentDemoUtils method newScheduledThreadPool.
/**
* Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.
*
* @param corePoolSize Number of threads to keep in the pool, even if they are idle.
* @param threadName Part of thread name that would be used by thread factory.
* @return Newly created scheduled thread pool.
*/
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, final String threadName) {
ScheduledExecutorService srvc = Executors.newScheduledThreadPool(corePoolSize, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, String.format("%s-%d", threadName, THREAD_CNT.getAndIncrement()));
thread.setDaemon(true);
return thread;
}
});
ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) srvc;
// Setting up shutdown policy.
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
return srvc;
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project toolkit by googleapis.
the class Pubsub method gapic.
private static void gapic(final Settings settings) throws Exception {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
// In real clients, InstantiatingChannelProvider is responsible for adding interceptors.
// We can't use it here because InstantiatingChannelProvider doesn't have sslContext method.
// Instead, we imitate HeaderInterceptor.
ClientInterceptor headerInterceptor = new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
return new SimpleForwardingClientCall<ReqT, RespT>(call) {
@Override
public void start(ClientCall.Listener<RespT> responseListener, Metadata headers) {
headers.put(X_GOOG_HEADER_KEY, X_GOOG_HEADER_VALUE);
super.start(responseListener, headers);
}
};
}
};
ManagedChannel channel = NettyChannelBuilder.forTarget(settings.endpoint()).executor(executor).sslContext(GrpcSslContexts.forClient().trustManager(new File(settings.cert())).build()).intercept(headerInterceptor).build();
final Semaphore semaphore = new Semaphore(settings.numWorkers());
final TopicAdminClient client = TopicAdminClient.create(TopicAdminSettings.defaultBuilder().setChannelProvider(FixedChannelProvider.create(channel)).setExecutorProvider(FixedExecutorProvider.create(executor)).build());
final AtomicLong resetTime = new AtomicLong();
final AtomicLong numCalls = new AtomicLong();
final AtomicLong numErrs = new AtomicLong();
long endTime = System.nanoTime() + settings.warmDurNano() + settings.targetDurNano();
Thread resetter = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(settings.warmDurNano() / MILLION);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
numCalls.set(0);
numErrs.set(0);
resetTime.set(System.nanoTime());
}
});
resetter.start();
while (System.nanoTime() < endTime) {
semaphore.acquire(1);
ApiFutures.addCallback(client.getTopicCallable().futureCall(GetTopicRequest.newBuilder().setTopicWithTopicName(TOPIC_NAME_RESOURCE).build()), new ApiFutureCallback<Topic>() {
@Override
public void onSuccess(Topic topic) {
if (!topic.getName().equals(TOPIC_NAME_STRING)) {
numErrs.incrementAndGet();
}
both();
}
@Override
public void onFailure(Throwable t) {
numErrs.incrementAndGet();
both();
}
void both() {
numCalls.incrementAndGet();
semaphore.release(1);
}
});
}
long nCalls = numCalls.get();
long nErrs = numErrs.get();
long runDurNano = System.nanoTime() - resetTime.get();
System.out.println("errors: " + nErrs);
System.out.println("calls: " + nCalls);
System.out.println("time per call (ns): " + (runDurNano / nCalls));
System.out.println("QPS: " + (nCalls * BILLION / runDurNano));
client.close();
channel.shutdown().awaitTermination(10, TimeUnit.SECONDS);
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
}
Aggregations