java.lang.System#currentTimeMillis ( )源码实例Demo

下面列出了java.lang.System#currentTimeMillis ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: java-example   文件: PubSubTest.java
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);
    }
}
 
源代码2 项目: ShadowsocksRR   文件: GuardedProcess.java
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;
}
 
源代码3 项目: Maying   文件: GuardedProcess.java
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;
}
 
源代码4 项目: java-example   文件: PubSubTest.java
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);
    }
}
 
源代码5 项目: android_9.0.0_r45   文件: Plog.java
/**
 * 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;
}