Java Utililty Methods TimeUnit Usage

List of utility methods to do TimeUnit Usage

Description

The list of methods to do TimeUnit Usage are organized into topic(s).

Method

booleanwaitFor(long period)
wait For
if (period > 0) {
    try {
        Thread.sleep(period);
    } catch (Exception e) {
        return false;
} else
    Thread.yield();
...
voidwaitFor(Object obj)
wait For
try {
    synchronized (obj) {
        obj.wait();
} catch (InterruptedException e) {
booleanwaitFor(Semaphore semaphore, long timeoutInMillis)
wait For
return semaphore.tryAcquire(timeoutInMillis, TimeUnit.MILLISECONDS);
voidwaitForMinutes(long time)
wait For Minutes
try {
    TimeUnit.MINUTES.sleep(time);
} catch (InterruptedException e) {
    e.printStackTrace();
intwaitForProcess(Process process, String name)
wait For Process
return waitForProcess(process, name, true);
TwaitForResponseObject(BlockingQueue queue, Class clazz)
Polls the blocking queue, waiting up to the POLLING_TIMEOUT (in seconds) if necessary for an element to become available.
return waitForResponseObject(queue, clazz, POLLING_TIMEOUT);
booleanwaitForSignal(CountDownLatch b)
wait For Signal
try {
    return b.await(timeoutSecs, TimeUnit.SECONDS);
} catch (InterruptedException ie) {
    return false;
longweekendMinutesBetween(Date date1, Date date2)
weekend Minutes Between
Calendar date1Calendar = Calendar.getInstance();
date1Calendar.setTime(date1);
long weekendMinutes = 0;
date1Calendar.add(Calendar.DAY_OF_MONTH, 1);
while (date2.after(date1Calendar.getTime())) {
    if (date1Calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
            || date1Calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
        weekendMinutes += TimeUnit.DAYS.toMinutes(1);
...
longzeroOutMs(long timestamp)
Cleans the milliseconds info from the timestamp
return SECONDS.toMillis(MILLISECONDS.toSeconds(timestamp));