001/*
002 * Copyright (c) 2015 Maxim Yunusov
003 *    Licensed under the Apache License, Version 2.0 (the "License");
004 *    you may not use this file except in compliance with the License.
005 *    You may obtain a copy of the License at
006 *
007 *        http://www.apache.org/licenses/LICENSE-2.0
008 *
009 *    Unless required by applicable law or agreed to in writing, software
010 *    distributed under the License is distributed on an "AS IS" BASIS,
011 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 *    See the License for the specific language governing permissions and
013 *    limitations under the License.
014 */
015
016package org.maxur.perfmodel.backend.utils;
017
018import java.util.Timer;
019import java.util.TimerTask;
020
021/**
022 * Date Time Utils class.
023 *
024 * @author myunusov
025 * @version 1.0
026 * @since <pre>01.09.2015</pre>
027 */
028public final class DateTimeUtils {
029
030    private DateTimeUtils() {
031    }
032
033    /**
034     * Postpone operation for delay milliseconds.
035     * While server sends stop request to client.
036     *
037     * @param operation postponed operation.
038     * @param delay duration of delay to operation.
039     * @return TimerTask see TimerTask
040     */
041    public static TimerTask schedule(final Runnable operation, long delay) {
042        final Timer timer = new Timer();
043        final TimerTask task = new TimerTask() {
044            public void run() {
045                operation.run();
046            }
047        };
048        timer.schedule(task, delay);
049        return task;
050    }
051}