Example usage for java.util.concurrent TimeUnit SECONDS

List of usage examples for java.util.concurrent TimeUnit SECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit SECONDS.

Prototype

TimeUnit SECONDS

To view the source code for java.util.concurrent TimeUnit SECONDS.

Click Source Link

Document

Time unit representing one second.

Usage

From source file:costumetrade.common.verify.CapthaService.java

@Override
public void save(String businessKey, String code) {

    String key = buildKey(businessKey);
    redisTemplate.opsForValue().set(key, code, 60, TimeUnit.SECONDS);

}

From source file:SecurityWatch.java

public void watchVideoCamera(Path path) throws IOException, InterruptedException {

    watchService = FileSystems.getDefault().newWatchService();
    register(path, StandardWatchEventKinds.ENTRY_CREATE);

    OUTERMOST: while (true) {

        final WatchKey key = watchService.poll(11, TimeUnit.SECONDS);

        if (key == null) {
            System.out.println("The video camera is jammed - security watch system is canceled!");
            break;
        } else {/* ww  w.j  a  v  a 2s .c om*/

            for (WatchEvent<?> watchEvent : key.pollEvents()) {

                final Kind<?> kind = watchEvent.kind();

                if (kind == StandardWatchEventKinds.OVERFLOW) {
                    continue;
                }

                if (kind == StandardWatchEventKinds.ENTRY_CREATE) {

                    //get the filename for the event
                    final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent;
                    final Path filename = watchEventPath.context();
                    final Path child = path.resolve(filename);

                    if (Files.probeContentType(child).equals("image/jpeg")) {

                        //print it out the video capture time
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
                        System.out.println("Video capture successfully at: " + dateFormat.format(new Date()));
                    } else {
                        System.out.println("The video camera capture format failed! This could be a virus!");
                        break OUTERMOST;
                    }
                }
            }

            boolean valid = key.reset();
            if (!valid) {
                break;
            }
        }
    }

    watchService.close();
}

From source file:MainClass.java

public SingleThreadAccess() {
    tpe = new ThreadPoolExecutor(1, 1, 50000L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
}

From source file:edu.umich.robot.util.Poses.java

public static pose_t elaborate(pose_t oldPose, pose_t newPose) {
    if (oldPose.utime == 0)
        return newPose;

    // elaborate to get velocities from odometry

    // (new usec - old usec) * 1 / usec in sec
    double dt = (newPose.utime - oldPose.utime) / (double) TimeUnit.MICROSECONDS.convert(1, TimeUnit.SECONDS);
    if (dt < MIN_ELABORATION_INTERVAL_SEC)
        return oldPose;

    // TODO: may need modification for smoothing
    newPose.vel[0] = (newPose.pos[0] - oldPose.pos[0]) * (1.0 / dt);
    newPose.vel[1] = (newPose.pos[1] - oldPose.pos[1]) * (1.0 / dt);

    double newTheta = LinAlg.quatToRollPitchYaw(newPose.orientation)[2];
    newTheta = MathUtil.mod2pi(newTheta);
    double oldTheta = LinAlg.quatToRollPitchYaw(oldPose.orientation)[2];
    oldTheta = MathUtil.mod2pi(oldTheta);
    newPose.rotation_rate[2] = MathUtil.mod2pi(newTheta - oldTheta) * (1.0 / dt);

    if (logger.isTraceEnabled()) {
        double xvel = LinAlg.rotate2(newPose.vel, -newTheta)[0];
        logger.trace(String.format("dt%1.5f vx%1.3f vy%1.3f r%1.3f xv%1.3f", dt, newPose.vel[0], newPose.vel[1],
                newPose.rotation_rate[2], xvel));
    }/*from  w  w  w  .  jav  a  2s .  com*/

    return newPose;
}

From source file:org.aevans.goat.net.IdleConnectionEvictor.java

@Override
public void run() {
    try {//from  w  w  w  .  j  a v  a 2  s.  c  om
        while (!shutdown) {
            synchronized (this) {
                wait(5000);
                // Close expired connections
                connMgr.closeExpiredConnections();
                // Optionally, close connections
                // that have been idle longer than 5 sec
                connMgr.closeIdleConnections(5, TimeUnit.SECONDS);
            }
        }
    } catch (InterruptedException ex) {

    }
}

From source file:de.micromata.mgc.application.webserver.config.KeyTool.java

public static void generateKey(ValContext ctx, File keyFile, String storePass, String keyAlias) {
    String[] args = { "keytool", "-genkey", "-alias", keyAlias, "-keyalg", "RSA", "-keystore",
            keyFile.getAbsolutePath(), "-keysize", "2048", "-keypass", storePass, "-storepass", storePass,
            "-dname", "cn=Launcher, ou=MGC, o=Microamta, c=DE" };
    StringBuilder oksb = new StringBuilder();
    oksb.append("Execute: " + StringUtils.join(args, " "));
    try {//  w  ww  . ja  v  a2 s  .  c om
        ProcessBuilder pb = new ProcessBuilder(args);
        pb.redirectErrorStream(true);
        Process process = pb.start();
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            oksb.append(line);
        }
        boolean success = process.waitFor(5, TimeUnit.SECONDS);
        if (success == false) {
            ctx.directError(null, "Fail to wait for keytool");
        } else {
            int exitValue = process.exitValue();
            if (exitValue == 0) {
                oksb.append("\nSuccess");
                ctx.directInfo(null, oksb.toString());
            } else {
                ctx.directError(null, oksb.toString());
                ctx.directError(null, "Failure executing keytool. ReturnCode: " + exitValue);
            }
        }
    } catch (Exception ex) {
        ctx.directError(null, "Failure executing keytool: " + ex.getMessage(), ex);
    }
}

From source file:com.yahoo.rdl.maven.ProcessRunner.java

public String run(List<String> command, ProcessBuilder processBuilder) throws IOException {
    Process process = processBuilder.start();
    try (StreamConsumer stdout = new StreamConsumer(process.getInputStream()).start()) {
        try (StreamConsumer stderr = new StreamConsumer(process.getErrorStream()).start()) {
            if (!process.waitFor(10, TimeUnit.SECONDS)) {
                throw new IOException("Process took longer than 10 seconds to execute: " + command);
            }/*w w w  .  j a v  a2s  . c  o m*/
            if (process.exitValue() != 0) {
                String s = stderr.getContents();
                throw new IOException("command '" + StringUtils.join(command, " ") + "' produced error: " + s);
            }
        }
        return stdout.getContents();
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }

}

From source file:simulation.LoadBalancer.java

public LoadBalancer() {
    vehicleLists = new ArrayList<>();
    generateArrayLists();/* w  w w.  j ava 2  s.com*/
    pulseGroup = 0;

    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    executor.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            pulseNextGroup();
        }
    }, 5, 2, TimeUnit.SECONDS);
}

From source file:costumetrade.common.verify.SmsService.java

@Override
public void save(String businessKey, String code) {
    String key = buildKey(businessKey);
    redisTemplate.opsForValue().set(key, code, 500, TimeUnit.SECONDS);
}

From source file:edu.cornell.mannlib.ld4lindexing.ThreadPool.java

public ThreadPool(Settings settings) {
    int poolSize = settings.getThreadPoolSize();
    int queueSize = settings.getTaskQueueSize();
    this.service = new ThreadPoolExecutor(poolSize, poolSize, 10, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(queueSize), new ThreadPoolExecutor.CallerRunsPolicy());
}