Java Code Examples for java.lang.System#currentTimeMillis()

The following examples show how to use java.lang.System#currentTimeMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PubSubTest.java    From java-example with MIT License 5 votes vote down vote up
protected Subscriber() {
    try {
        desktopConnection = new DesktopConnection(UUID.randomUUID().toString());
        this.statsThread = new Thread() {
            public void run() {
                long sleepTime = 10000;
                String value = java.lang.System.getProperty("com.openfin.demo.stats.frequency");
                if (value != null) {
                    sleepTime = Long.parseLong(value) * 1000;
                }
                while (true) {
                    try {
                        Thread.sleep(sleepTime);
                        if (totalReceived > 0) {
                            long rate = totalReceived / ((System.currentTimeMillis() - startTime) / 1000);
                            logger.info(String.format("Total Received %d Rate %d", totalReceived, rate));
                        } else {
                            logger.info("Waiting for messages");
                        }
                    } catch (InterruptedException e) {
                        logger.error("Error", e);
                    }
                }
            }
        };
        this.statsThread.setDaemon(false);
        this.statsThread.start();

    }catch (Exception ex) {
        logger.error("Error creating subscriber", ex);
    }
}
 
Example 2
Source File: GuardedProcess.java    From ShadowsocksRR with Apache License 2.0 4 votes vote down vote up
public GuardedProcess start(final RestartCallback onRestartCallback) throws InterruptedException {
    final Semaphore semaphore = new Semaphore(1);
    semaphore.acquire();

    guardThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                RestartCallback callback = null;
                while (!isDestroyed) {
                    VayLog.i(TAG, "start process: " + cmd);
                    long startTime = System.currentTimeMillis();

                    process = new ProcessBuilder(cmd).redirectErrorStream(true).start();

                    InputStream is = process.getInputStream();
                    new StreamLogger(is, TAG).start();

                    if (callback == null) {
                        callback = onRestartCallback;
                    } else {
                        callback.onRestart();
                    }

                    semaphore.release();
                    process.waitFor();

                    synchronized (this) {
                        if (isRestart) {
                            isRestart = false;
                        } else {
                            if (System.currentTimeMillis() - startTime < 1000) {
                                Log.w(TAG, "process exit too fast, stop guard: " + cmd);
                                isDestroyed = true;
                            }
                        }
                    }

                }
            } catch (Exception ignored) {
                VayLog.i(TAG, "thread interrupt, destroy process: " + cmd);
                process.destroy();
            } finally {
                semaphore.release();
            }
        }
    }, "GuardThread-" + cmd);

    guardThread.start();
    semaphore.acquire();
    return this;
}
 
Example 3
Source File: GuardedProcess.java    From Maying with Apache License 2.0 4 votes vote down vote up
public GuardedProcess start(final RestartCallback onRestartCallback) throws InterruptedException {
    final Semaphore semaphore = new Semaphore(1);
    semaphore.acquire();

    guardThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                RestartCallback callback = null;
                while (!isDestroyed) {
                    VayLog.i(TAG, "start process: " + cmd);
                    long startTime = System.currentTimeMillis();

                    process = new ProcessBuilder(cmd).redirectErrorStream(true).start();

                    InputStream is = process.getInputStream();
                    new StreamLogger(is, TAG).start();

                    if (callback == null) {
                        callback = onRestartCallback;
                    } else {
                        callback.onRestart();
                    }

                    semaphore.release();
                    process.waitFor();

                    synchronized (this) {
                        if (isRestart) {
                            isRestart = false;
                        } else {
                            if (System.currentTimeMillis() - startTime < 1000) {
                                Log.w(TAG, "process exit too fast, stop guard: " + cmd);
                                isDestroyed = true;
                            }
                        }
                    }

                }
            } catch (Exception ignored) {
                VayLog.i(TAG, "thread interrupt, destroy process: " + cmd);
                if (process!=null) {
                    process.destroy();
                }
            } finally {
                semaphore.release();
            }
        }
    }, "GuardThread-" + cmd);

    guardThread.start();
    semaphore.acquire();
    return this;
}
 
Example 4
Source File: PubSubTest.java    From java-example with MIT License 4 votes vote down vote up
Publisher() {
    try {
        String value = java.lang.System.getProperty("com.openfin.demo.publish.frequency");
        if (value != null) {
            this.publishFrequency = Long.parseLong(value);
        } else {
            this.publishFrequency = 200;
        }
        value = java.lang.System.getProperty("com.openfin.demo.publish.size");
        if (value != null) {
            this.publishMessageSize = Long.parseLong(value);
        } else {
            this.publishMessageSize = 1024;
        }
        value = java.lang.System.getProperty("com.openfin.demo.publish.threads");
        if (value != null) {
            this.threadCount = Integer.parseInt(value);
        } else {
            this.threadCount = 1;
        }
        this.body = createMessageBody(this.publishMessageSize);
        publishTimers = new ArrayList<Timer>();
        for (int i = 0; i < this.threadCount; i++) {
            this.publishTimers.add(new java.util.Timer());
        }
        desktopConnection = new DesktopConnection(UUID.randomUUID().toString());

        this.statsThread = new Thread() {
            public void run() {
                long sleepTime = 10000;
                String value = java.lang.System.getProperty("com.openfin.demo.stats.frequency");
                if (value != null) {
                    sleepTime = Long.parseLong(value) * 1000;
                }
                while (true) {
                    try {
                        Thread.sleep(sleepTime);
                        if (totalSent > 0) {
                            long rate = totalSent / ((System.currentTimeMillis() - startTime) / 1000);
                            logger.info(String.format("Total Sent %d Rate %d", totalSent, rate));
                        }
                    } catch (InterruptedException e) {
                        logger.error("Error", e);
                    }
                }
            }
        };
        this.statsThread.setDaemon(false); // keep running
        this.statsThread.start();

    }catch (Exception ex) {
        logger.error("Error creating publisher", ex);
    }
}
 
Example 5
Source File: Plog.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Start a new plot.
 *
 * @param title The plot title.
 * @return The Plog instance (for chaining).
 */
public Plog start(String title) {
    mId = System.currentTimeMillis();
    write(formatTitle(title));
    return this;
}