Search in sources :

Example 21 with Timer

use of java.util.Timer in project hive by apache.

the class HeartbeatFactory method newInstance.

/** Creates a new {@link HeartbeatTimerTask} instance for the {@link Lock} and schedules it. */
Timer newInstance(IMetaStoreClient metaStoreClient, LockFailureListener listener, Long transactionId, Collection<Table> tableDescriptors, long lockId, int heartbeatPeriod) {
    Timer heartbeatTimer = new Timer("hive-lock-heartbeat[lockId=" + lockId + ", transactionId=" + transactionId + "]", true);
    HeartbeatTimerTask task = new HeartbeatTimerTask(metaStoreClient, listener, transactionId, tableDescriptors, lockId);
    heartbeatTimer.schedule(task, TimeUnit.SECONDS.toMillis(heartbeatPeriod), TimeUnit.SECONDS.toMillis(heartbeatPeriod));
    LOG.debug("Scheduled heartbeat timer task: {}", heartbeatTimer);
    return heartbeatTimer;
}
Also used : Timer(java.util.Timer)

Example 22 with Timer

use of java.util.Timer in project hive by apache.

the class ScriptOperator method close.

@Override
public void close(boolean abort) throws HiveException {
    boolean new_abort = abort;
    if (!abort) {
        if (scriptError != null) {
            throw new HiveException(ErrorMsg.SCRIPT_GENERIC_ERROR.getErrorCodedMsg(), scriptError);
        }
        // everything ok. try normal shutdown
        try {
            try {
                if (scriptOutWriter != null) {
                    scriptOutWriter.close();
                }
            } catch (IOException e) {
                if (isBrokenPipeException(e) && allowPartialConsumption()) {
                    LOG.warn("Got broken pipe: ignoring exception");
                } else {
                    if (isBrokenPipeException(e)) {
                        displayBrokenPipeInfo();
                    }
                    throw e;
                }
            }
            int exitVal = 0;
            if (scriptPid != null) {
                exitVal = scriptPid.waitFor();
            }
            if (exitVal != 0) {
                LOG.error("Script failed with code " + exitVal);
                new_abort = true;
            }
        } catch (IOException e) {
            LOG.error("Got ioexception: " + e.getMessage());
            e.printStackTrace();
            new_abort = true;
        } catch (InterruptedException e) {
        }
    } else {
        // error code of the child process if possible.
        try {
            // Interrupt the current thread after 1 second
            final Thread mythread = Thread.currentThread();
            Timer timer = new Timer(true);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    mythread.interrupt();
                }
            }, 1000);
            // Wait for the child process to finish
            int exitVal = 0;
            if (scriptPid != null) {
                scriptPid.waitFor();
            }
            // Cancel the timer
            timer.cancel();
            // Output the exit code
            LOG.error("Script exited with code " + exitVal);
        } catch (InterruptedException e) {
            // Ignore
            LOG.error("Script has not exited yet. It will be killed.");
        }
    }
    // try these best effort
    try {
        if (outThread != null) {
            outThread.join(0);
        }
    } catch (Exception e) {
        LOG.warn("Exception in closing outThread: " + StringUtils.stringifyException(e));
    }
    try {
        if (errThread != null) {
            errThread.join(0);
        }
    } catch (Exception e) {
        LOG.warn("Exception in closing errThread: " + StringUtils.stringifyException(e));
    }
    try {
        if (scriptPid != null) {
            scriptPid.destroy();
        }
    } catch (Exception e) {
        LOG.warn("Exception in destroying scriptPid: " + StringUtils.stringifyException(e));
    }
    super.close(new_abort);
    if (new_abort && !abort) {
        throw new HiveException(ErrorMsg.SCRIPT_CLOSING_ERROR.getErrorCodedMsg());
    }
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) IOException(java.io.IOException) IOException(java.io.IOException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException)

Example 23 with Timer

use of java.util.Timer in project zeppelin by apache.

the class ZeppelinClient method addRoutines.

private void addRoutines() {
    schedulerService.add(ZeppelinHeartbeat.newInstance(this), 10, 1 * MIN);
    new Timer().schedule(new java.util.TimerTask() {

        @Override
        public void run() {
            watcherSession = openWatcherSession();
        }
    }, 5000);
}
Also used : Timer(java.util.Timer)

Example 24 with Timer

use of java.util.Timer in project UltimateAndroid by cymcsg.

the class CircleProgressActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.circle_progress_activity_my);
    donutProgress = (DonutProgress) findViewById(R.id.donut_progress);
    circleProgress = (CircleProgress) findViewById(R.id.circle_progress);
    arcProgress = (ArcProgress) findViewById(R.id.arc_progress);
    timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    donutProgress.setProgress(donutProgress.getProgress() + 1);
                    circleProgress.setProgress(circleProgress.getProgress() + 1);
                    arcProgress.setProgress(arcProgress.getProgress() + 1);
                }
            });
        }
    }, 1000, 100);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 25 with Timer

use of java.util.Timer in project PlayerHater by chrisrhoden.

the class PlaylistSupportingPlayer method startWithFade.

public void startWithFade() throws IllegalStateException {
    setVolume(0, 0);
    start();
    final Timer timer = new Timer(true);
    TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            setVolume(mLeftVolume + 0.1f, mRightVolume + 01.f);
            if (mLeftVolume >= 1.0f || mRightVolume >= 1.0f) {
                timer.cancel();
                timer.purge();
            }
        }
    };
    timer.schedule(timerTask, 200, 200);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Aggregations

Timer (java.util.Timer)448 TimerTask (java.util.TimerTask)262 IOException (java.io.IOException)33 Date (java.util.Date)22 Test (org.junit.Test)15 File (java.io.File)11 ArrayList (java.util.ArrayList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9 Intent (android.content.Intent)8 Location (android.location.Location)8 LocationListener (android.location.LocationListener)8 Bundle (android.os.Bundle)8 ActivitiException (org.activiti.engine.ActivitiException)8 View (android.view.View)7 InputMethodManager (android.view.inputmethod.InputMethodManager)7 ImageView (android.widget.ImageView)7 BufferedReader (java.io.BufferedReader)7 InputStreamReader (java.io.InputStreamReader)7