本文整理匯總了Java中org.apache.commons.lang.time.DateUtils.addSeconds方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.addSeconds方法的具體用法?Java DateUtils.addSeconds怎麽用?Java DateUtils.addSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.time.DateUtils
的用法示例。
在下文中一共展示了DateUtils.addSeconds方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fireCronTrigger
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
private boolean fireCronTrigger(TriggerKey triggerKey, JobDetail jobDetail, String cron, boolean replace, Map<String, Object> dataMap) {
try {
boolean isExists = clusterScheduler.checkExists(triggerKey);
if (isExists) {
if (replace) {
logger.warn("replace trigger={}:{} ", triggerKey.getName(), triggerKey.getGroup());
clusterScheduler.unscheduleJob(triggerKey);
} else {
logger.info("exist trigger={}:{} ", triggerKey.getName(), triggerKey.getGroup());
return false;
}
}
Date startDate = DateUtils.addSeconds(new Date(), 20);
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(triggerKey)
.forJob(jobDetail)
.withSchedule(
CronScheduleBuilder.cronSchedule(cron)
.withMisfireHandlingInstructionDoNothing()// 忽略misfire處理
)
.startAt(startDate)
.build();
if (dataMap != null && dataMap.size() > 0) {
trigger.getJobDataMap().putAll(dataMap);
}
clusterScheduler.scheduleJob(trigger);
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
return false;
}
return true;
}
示例2: testExpiry
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
@Test(timeout=120000)
public void testExpiry() throws Exception {
String pool = "pool1";
dfs.addCachePool(new CachePoolInfo(pool));
Path p = new Path("/mypath");
DFSTestUtil.createFile(dfs, p, BLOCK_SIZE*2, (short)2, 0x999);
// Expire after test timeout
Date start = new Date();
Date expiry = DateUtils.addSeconds(start, 120);
final long id = dfs.addCacheDirective(new CacheDirectiveInfo.Builder()
.setPath(p)
.setPool(pool)
.setExpiration(CacheDirectiveInfo.Expiration.newAbsolute(expiry))
.setReplication((short)2)
.build());
waitForCachedBlocks(cluster.getNameNode(), 2, 4, "testExpiry:1");
// Change it to expire sooner
dfs.modifyCacheDirective(new CacheDirectiveInfo.Builder().setId(id)
.setExpiration(Expiration.newRelative(0)).build());
waitForCachedBlocks(cluster.getNameNode(), 0, 0, "testExpiry:2");
RemoteIterator<CacheDirectiveEntry> it = dfs.listCacheDirectives(null);
CacheDirectiveEntry ent = it.next();
assertFalse(it.hasNext());
Date entryExpiry = new Date(ent.getInfo().getExpiration().getMillis());
assertTrue("Directive should have expired",
entryExpiry.before(new Date()));
// Change it back to expire later
dfs.modifyCacheDirective(new CacheDirectiveInfo.Builder().setId(id)
.setExpiration(Expiration.newRelative(120000)).build());
waitForCachedBlocks(cluster.getNameNode(), 2, 4, "testExpiry:3");
it = dfs.listCacheDirectives(null);
ent = it.next();
assertFalse(it.hasNext());
entryExpiry = new Date(ent.getInfo().getExpiration().getMillis());
assertTrue("Directive should not have expired",
entryExpiry.after(new Date()));
// Verify that setting a negative TTL throws an error
try {
dfs.modifyCacheDirective(new CacheDirectiveInfo.Builder().setId(id)
.setExpiration(Expiration.newRelative(-1)).build());
} catch (InvalidRequestException e) {
GenericTestUtils
.assertExceptionContains("Cannot set a negative expiration", e);
}
}
示例3: loadEmailsToSend
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
protected List<SendingMessage> loadEmailsToSend() {
Date sendTimeoutTime = DateUtils.addSeconds(timeSource.currentTimestamp(), -config.getSendingTimeoutSec());
List<SendingMessage> emailsToSend = new ArrayList<>();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
TypedQuery<SendingMessage> query = em.createQuery(
"select sm from sys$SendingMessage sm" +
" where sm.status = :statusQueue or (sm.status = :statusSending and sm.updateTs < :time)" +
" order by sm.createTs",
SendingMessage.class
);
query.setParameter("statusQueue", SendingStatus.QUEUE.getId());
query.setParameter("time", sendTimeoutTime);
query.setParameter("statusSending", SendingStatus.SENDING.getId());
View view = metadata.getViewRepository().getView(SendingMessage.class, "sendingMessage.loadFromQueue");
view.setLoadPartialEntities(true); // because SendingAttachment.content has FetchType.LAZY
query.setView(view);
query.setMaxResults(config.getMessageQueueCapacity());
List<SendingMessage> resList = query.getResultList();
for (SendingMessage msg : resList) {
if (shouldMarkNotSent(msg)) {
msg.setStatus(SendingStatus.NOTSENT);
} else {
msg.setStatus(SendingStatus.SENDING);
emailsToSend.add(msg);
}
}
tx.commit();
}
for (SendingMessage message : emailsToSend) {
loadBodyAndAttachments(message);
}
return emailsToSend;
}
示例4: addSeconds
import org.apache.commons.lang.time.DateUtils; //導入方法依賴的package包/類
/**
* 給指定日期加幾秒
*
* @param date
* 指定的日期
* @param numSeconds
* 需要往後加的秒數
* @return 加好後的日期
*/
public static Date addSeconds(Date date, int numSeconds) {
Assert.notNull(date);
return DateUtils.addSeconds(date, numSeconds);
}