本文整理匯總了Java中java.util.concurrent.ScheduledExecutorService.scheduleWithFixedDelay方法的典型用法代碼示例。如果您正苦於以下問題:Java ScheduledExecutorService.scheduleWithFixedDelay方法的具體用法?Java ScheduledExecutorService.scheduleWithFixedDelay怎麽用?Java ScheduledExecutorService.scheduleWithFixedDelay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.ScheduledExecutorService
的用法示例。
在下文中一共展示了ScheduledExecutorService.scheduleWithFixedDelay方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: HTTPconThread
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
public HTTPconThread(int id,URLdetails obj,int time){
this.obj=obj;
this.id = id;
this.time=time;
this.index = Controller.getList().indexOf(obj);
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
if(Controller.getList().indexOf(obj)==-1){
executorService.shutdown();
}
testIt(obj.getUrl());
}
}, 0, time, TimeUnit.SECONDS);
}
示例2: sendMsg
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
public void sendMsg() {
System.out.println("sendMsg");
ScheduledExecutorService newScheduledThreadPool = Executors.newSingleThreadScheduledExecutor();
Random random = new Random();
// int delay = random.nextInt(2) + 1;
int delay = 3;
System.out.println("delay = " + delay);
newScheduledThreadPool.scheduleWithFixedDelay(new Monitor(), 1, delay, TimeUnit.SECONDS);
}
示例3: postConstruct
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
@PostConstruct
private void postConstruct() {
allEnvs = portalConfig.portalSupportedEnvs();
for (Env env : allEnvs) {
envStatusMark.put(env, true);
}
ScheduledExecutorService
healthCheckService =
Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("EnvHealthChecker", false));
healthCheckService
.scheduleWithFixedDelay(new HealthCheckTask(applicationContext), 1000, HEALTH_CHECK_INTERVAL,
TimeUnit.MILLISECONDS);
}
示例4: startCredentialRefresher
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
/**
* startCredentialRefresher should be used only for long running
* methods like Thrift source. For all privileged methods that use a UGI, the
* credentials are checked automatically and refreshed before the
* privileged method is executed in the UGIExecutor
*/
@Override
public void startCredentialRefresher() {
int CHECK_TGT_INTERVAL = 120; // seconds
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
ugi.checkTGTAndReloginFromKeytab();
} catch (IOException e) {
LOG.warn("Error occured during checkTGTAndReloginFromKeytab() for user " +
ugi.getUserName(), e);
}
}
}, CHECK_TGT_INTERVAL, CHECK_TGT_INTERVAL, TimeUnit.SECONDS);
}
示例5: createLogSyncer
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
public static ScheduledExecutorService createLogSyncer() {
final ScheduledExecutorService scheduler =
Executors.newSingleThreadScheduledExecutor(
new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
final Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
t.setName("Thread for syncLogs");
return t;
}
});
ShutdownHookManager.get().addShutdownHook(new Runnable() {
@Override
public void run() {
TaskLog.syncLogsShutdown(scheduler);
}
}, 50);
scheduler.scheduleWithFixedDelay(
new Runnable() {
@Override
public void run() {
TaskLog.syncLogs();
}
}, 0L, 5L, TimeUnit.SECONDS);
return scheduler;
}
示例6: RequestSignatureRuleImpl
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
public RequestSignatureRuleImpl ( final ScheduledExecutorService executor, final SignatureRequestBuilder builder, final RequestValidator validator, final X509KeySelector keySelector, final AuditLogService auditLogService, final boolean indent, final ScriptExecutor postProcessor, final AuthenticationImplementation authenticator, final int reloadPeriod )
{
this.builder = builder;
this.validator = validator;
this.auditLogService = auditLogService;
this.indent = indent;
this.postProcessor = postProcessor;
this.authenticator = authenticator;
this.keySelector = keySelector;
if ( reloadPeriod > 0 )
{
logger.debug ( "Starting reload job: {} ms", reloadPeriod );
this.job = executor.scheduleWithFixedDelay ( new Runnable () {
@Override
public void run ()
{
reload ();
}
}, 0, reloadPeriod, TimeUnit.MILLISECONDS );
}
else
{
logger.debug ( "Reloading once" );
reload ();
}
}
示例7: main
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
public static void main(String[] args) {
MeterRegistry registry = SampleConfig.myMonitoringSystem();
ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
new ExecutorServiceMetrics(es, "executor.sample", emptyList()).bindTo(registry);
es.scheduleWithFixedDelay(() -> Mono.delay(Duration.ofMillis(20)).block(), 0,
10, TimeUnit.MILLISECONDS);
while(true) {}
}
示例8: newFixedDelaySchedule
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
/**
* Returns a {@link Scheduler} that schedules the task using the {@link
* ScheduledExecutorService#scheduleWithFixedDelay} method.
*
* @param initialDelay the time to delay first execution
* @param delay the delay between the termination of one execution and the commencement of the
* next
* @param unit the time unit of the initialDelay and delay parameters
*/
public static Scheduler newFixedDelaySchedule(
final long initialDelay, final long delay, final TimeUnit unit) {
checkNotNull(unit);
checkArgument(delay > 0, "delay must be > 0, found %s", delay);
return new Scheduler() {
@Override
public Future<?> schedule(
AbstractService service, ScheduledExecutorService executor, Runnable task) {
return executor.scheduleWithFixedDelay(task, initialDelay, delay, unit);
}
};
}
示例9: FDTServer
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
public FDTServer(int port) throws Exception {
hasToRun = new AtomicBoolean(true);
// We are not very happy to welcome new clients ... so the priority will be lower
executor = Utils.getStandardExecService("[ Acceptable ServersThreadPool ] ",
5,
10,
new ArrayBlockingQueue<Runnable>(65500),
Thread.NORM_PRIORITY - 2);
ssc = ServerSocketChannel.open();
ssc.configureBlocking(false);
ss = ssc.socket();
String listenIP = config.getListenAddress();
if (listenIP == null) {
ss.bind(new InetSocketAddress(port));
}
else
{
ss.bind(new InetSocketAddress(InetAddress.getByName(listenIP), port));
}
sel = Selector.open();
ssc.register(sel, SelectionKey.OP_ACCEPT);
if (config.isGSIModeEnabled()) {
FDTGSIServer gsiServer = new FDTGSIServer(config.getGSIPort());
gsiServer.start();
logger.log(Level.INFO, "FDT started in GSI mode on port: " + config.getGSIPort());
}
// Monitoring & Nice Prnting
final ScheduledExecutorService monitoringService = Utils.getMonitoringExecService();
monitoringService.scheduleWithFixedDelay(new FDTServerMonitorTask(), 10, 10, TimeUnit.SECONDS);
// in SSH mode this is a ACK message for the client to inform it that the server started ok
// (the server stdout is piped to client through the SSH channel)
System.out.println("READY");
}
示例10: fixedRate
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
private static void fixedRate() throws Exception {
// starts immediately after the task has run
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
Runnable task = () -> {
System.out.println("Scheduling: " + System.nanoTime() + " " + ZonedDateTime.now());
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Ready: " + System.nanoTime() + " " + ZonedDateTime.now());
};
int initialDelay = 0;
int period = 8;
executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
ScheduledExecutorService watch = Executors.newScheduledThreadPool(1);
Runnable watcher = () -> {
if (new File("stop").exists()) {
System.out.println("Stopping executor because file 'stop' exists.");
executor.shutdown();
watch.shutdown();
}
};
watch.scheduleWithFixedDelay(watcher, 1, 1, TimeUnit.SECONDS);
}
示例11: init
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
/**
* creates the scheduledExecutor thread pool and starts schedule timers which
* check for expired entry timers and adjust the message display timer
*/
public void init()
{
/* thread to fill announcement queues and thread to empty announcement queues,
share the same scheduler to avoid collisions */
ScheduledExecutorService announcementScheduler = Executors.newSingleThreadScheduledExecutor();
// fill
announcementScheduler.scheduleWithFixedDelay(
new EntryProcessor(type.FILL),
30, 30, TimeUnit.SECONDS);
// empty
announcementScheduler.scheduleWithFixedDelay(
new EntryProcessor(type.EMPTY),
15, 20, TimeUnit.SECONDS);
// scheduler for threads to adjust entry display timers
ScheduledExecutorService updateDisplayScheduler = Executors.newSingleThreadScheduledExecutor();
// 1 day timer
updateDisplayScheduler.scheduleWithFixedDelay(
new EntryProcessor(type.UPDATE3),
12*60*60, 12*60*60, TimeUnit.SECONDS);
// 1 hour timer
updateDisplayScheduler.scheduleWithFixedDelay(
new EntryProcessor(type.UPDATE2),
60*30, 60*30, TimeUnit.SECONDS);
// 4.5 min timer
updateDisplayScheduler.scheduleWithFixedDelay(
new EntryProcessor(type.UPDATE1),
60*4+30, 60*3, TimeUnit.SECONDS);
}
示例12: setupPseudoDNSServer
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
private void setupPseudoDNSServer() {
hasStaticIp = false;
ipRefreshURL = "http://hartzkai.freehostia.com/thesis/changeip.php";
final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
ses.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
String urlParameters = "";
NetworkUtilities.executePost(ipRefreshURL, urlParameters);
// System.out.println("Refreshed Ip at:" + ipRefreshURL);
}
}, 0, 1, TimeUnit.MINUTES);
}
示例13: scheduleWithFixedDelay
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
ScheduledExecutorService executor = getScheduledExecutor();
long initialDelay = startTime.getTime() - System.currentTimeMillis();
try {
return executor.scheduleWithFixedDelay(errorHandlingTask(task, true), initialDelay, delay, TimeUnit.MILLISECONDS);
}
catch (RejectedExecutionException ex) {
throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
}
}
示例14: startMongoServerThread
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
private static void startMongoServerThread(){
ms= new MongoSender(collection);
ScheduledExecutorService scheduledExecutorService2 =
Executors.newScheduledThreadPool(1);
ScheduledFuture scheduledFuture2 =
scheduledExecutorService2.scheduleWithFixedDelay(ms, 1, 5, TimeUnit.MINUTES);
}
示例15: main
import java.util.concurrent.ScheduledExecutorService; //導入方法依賴的package包/類
/**
* Runs the application as a giveaway updater
* @throws Exception
*/
public static void main() throws Exception
{
LoggerFactory.getLogger("Updater").info("Updater starting.");
// load tokens from a file
// 0 - bot token
// 1 - database host
// 2 - database username
// 3 - database pass
List<String> tokens = Files.readAllLines(Paths.get("updater.txt"));
// connects to the database
Database database = new Database(tokens.get(1), tokens.get(2), tokens.get(3));
// migrate the old giveaways if the file exists
//migrateGiveaways(database);
// make a 'JDA' rest client
RestJDA restJDA = new RestJDA(tokens.get(0));
// make a pool to run the update loop
ScheduledExecutorService pool = Executors.newSingleThreadScheduledExecutor();
// create an index to track time
AtomicLong index = new AtomicLong(0);
pool.scheduleWithFixedDelay(() -> {
// set vars for this iteration
long current = index.getAndIncrement();
Instant now = Instant.now();
// end giveaways with end status
database.giveaways.getGiveaways(Status.ENDNOW).forEach(giveaway -> {
database.giveaways.deleteGiveaway(giveaway.messageId);
giveaway.end(restJDA);
});
// end giveaways that have run out of time
database.giveaways.getGiveawaysEndingBefore(now.plusMillis(1900)).forEach(giveaway -> {
database.giveaways.deleteGiveaway(giveaway.messageId);
giveaway.end(restJDA);
});
if(current%300==0)
{
// update all giveaways
database.giveaways.getGiveaways().forEach(giveaway -> giveaway.update(restJDA, database, now));
}
else if(current%60==0)
{
// update giveaways within 1 hour of ending
database.giveaways.getGiveawaysEndingBefore(now.plusSeconds(60*60)).forEach(giveaway -> giveaway.update(restJDA, database, now));
}
else if(current%5==0)
{
// update giveaways within 3 minutes of ending
database.giveaways.getGiveawaysEndingBefore(now.plusSeconds(3*60)).forEach(giveaway -> giveaway.update(restJDA, database, now));
}
else
{
// update giveaways within 10 seconds of ending
database.giveaways.getGiveawaysEndingBefore(now.plusSeconds(6)).forEach(giveaway -> giveaway.update(restJDA, database, now));
}
}, 0, 1, TimeUnit.SECONDS);
}