Example usage for java.lang Thread hashCode

List of usage examples for java.lang Thread hashCode

Introduction

In this page you can find the example usage for java.lang Thread hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:Main.java

/**
 * Returns a readable name of the current executing thread.
 *///w w w .jav a 2s. co m
public static final String currentThreadInfo() {
    Thread thread = Thread.currentThread();
    return String.valueOf(thread.getName() + "@" + thread.hashCode());
}

From source file:com.tascape.qa.th.Utils.java

public static void waitForOutputLine(final Process process, String lineExpected, final long timeout)
        throws IOException {
    Thread t = new Thread() {
        @Override/* w w  w. ja  v a  2s.c om*/
        public void run() {
            try {
                Thread.sleep(timeout);
            } catch (InterruptedException ex) {
                LOG.warn(ex.getMessage());
            } finally {
                if (process != null) {
                    process.destroy();
                }
            }
        }
    };
    t.setName(Thread.currentThread().getName() + "-" + t.hashCode());
    t.setDaemon(true);
    t.start();

    try (BufferedReader stdIn = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
        for (String line = stdIn.readLine(); line != null;) {
            if (line.contains(lineExpected)) {
                break;
            }
            line = stdIn.readLine();
        }
    }
    t.interrupt();
}

From source file:com.tascape.qa.th.Utils.java

/**
 *
 * @param path          directory to clean
 * @param keepAliveHour any file/directory having last modified time longer than keepAliveHour will be deleted
 * @param namePrefix    file name prefix
 *///from   w  w  w.  ja  va2s.c o  m
public static void cleanDirectory(final String path, final float keepAliveHour, final String namePrefix) {
    final long intervalMillis = 3600000;
    final File dir = new File(path);
    if (!dir.exists()) {
        return;
    }
    Thread thread = new Thread() {
        @Override
        public void run() {
            while (true) {
                long lastModifiedMillis = (long) (System.currentTimeMillis() - keepAliveHour * 3600000);
                Collection<File> files = FileUtils.listFiles(dir, null, true);
                for (File file : files) {
                    if (file.lastModified() < lastModifiedMillis && file.getName().startsWith(namePrefix)) {
                        LOG.debug("Delete {}", file);
                        if (!FileUtils.deleteQuietly(file)) {
                            LOG.debug("Cannot delete {}", file);
                        }
                    }
                }
                try {
                    LOG.debug("Waiting for next cleanup...");
                    Thread.sleep(intervalMillis);
                } catch (InterruptedException ex) {
                    LOG.warn(ex.getMessage());
                    return;
                }
            }
        }
    };
    thread.setName(Thread.currentThread().getName() + "-cleaning-" + thread.hashCode());
    thread.setDaemon(true);
    LOG.info(
            "Starting directory cleaning thread (scanning hourly), all files/directories in {} and older than {} "
                    + "hour(s) and starts with {} will be deleted",
            dir, keepAliveHour, namePrefix);
    thread.start();
}

From source file:io.reign.zk.ResilientZkClient.java

synchronized void spawnReconnectThread() {
    if (zooKeeper == null || zooKeeper.getState() == ZooKeeper.States.CLOSED) {
        // do connection in another thread so as to not block the ZK event thread
        Thread reconnectThread = new Thread() {
            @Override//  w w  w  .j av  a2 s  .  c  o m
            public void run() {
                connect(backoffStrategyFactory.get(), true);
            }
        };
        reconnectThread
                .setName(this.getClass().getSimpleName() + ".zkConnectThread-" + reconnectThread.hashCode());
        reconnectThread.setPriority(Thread.MIN_PRIORITY);
        reconnectThread.run();
    }
}

From source file:com.workplacesystems.utilsj.collections.TransactionalBidiTreeMap.java

/**
 * Retrieve the current thread id for use by the
 * transaction code./*ww w. jav  a 2  s  .  com*/
 *
 * @return the thread id of the current thread
 */
protected String getCurrentThreadId() {

    String attach_id = (String) ThreadSession.getValue(getThreadSessionKey());
    if (attach_id != null)
        return attach_id;

    Thread thread = Thread.currentThread();
    return thread.toString() + "(" + thread.hashCode() + ")";
}