Example usage for java.lang Thread getName

List of usage examples for java.lang Thread getName

Introduction

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

Prototype

public final String getName() 

Source Link

Document

Returns this thread's name.

Usage

From source file:org.apache.rya.accumulo.mr.merge.MergeTool.java

public static void main(final String[] args) {
    final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration");
    if (StringUtils.isNotBlank(log4jConfiguration)) {
        final String parsedConfiguration = StringUtils.removeStart(log4jConfiguration, "file:");
        final File configFile = new File(parsedConfiguration);
        if (configFile.exists()) {
            DOMConfigurator.configure(parsedConfiguration);
        } else {/*  w  w w  . j  a  va2 s .  c  om*/
            BasicConfigurator.configure();
        }
    }
    log.info("Starting Merge Tool");

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread thread, final Throwable throwable) {
            log.error("Uncaught exception in " + thread.getName(), throwable);
        }
    });

    final int returnCode = setupAndRun(args);

    log.info("Finished running Merge Tool");

    System.exit(returnCode);
}

From source file:com.amazon.kinesis.streaming.agent.Agent.java

public static void main(String[] args) throws Exception {
    AgentOptions opts = AgentOptions.parse(args);
    String configFile = opts.getConfigFile();
    AgentConfiguration config = tryReadConfigurationFile(Paths.get(opts.getConfigFile()));
    Path logFile = opts.getLogFile() != null ? Paths.get(opts.getLogFile())
            : (config != null ? config.logFile() : null);
    String logLevel = opts.getLogLevel() != null ? opts.getLogLevel()
            : (config != null ? config.logLevel() : null);
    int logMaxBackupFileIndex = (config != null ? config.logMaxBackupIndex() : -1);
    long logMaxFileSize = (config != null ? config.logMaxFileSize() : -1L);
    Logging.initialize(logFile, logLevel, logMaxBackupFileIndex, logMaxFileSize);
    final Logger logger = Logging.getLogger(Agent.class);

    // Install an unhandled exception hook
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override//from w w  w . jav a 2 s  . c  o  m
        public void uncaughtException(Thread t, Throwable e) {
            if (e instanceof OutOfMemoryError) {
                // This prevents the JVM from hanging in case of an OOME
                dontShutdownOnExit = true;
            }
            String msg = "FATAL: Thread " + t.getName() + " threw an unrecoverable error. Aborting application";
            try {
                try { // We don't know if logging is still working
                    logger.error(msg, e);
                } finally {
                    System.err.println(msg);
                    e.printStackTrace();
                }
            } finally {
                System.exit(1);
            }
        }
    });

    try {
        logger.info("Reading configuration from file: {}", configFile);
        if (config == null) {
            config = readConfigurationFile(Paths.get(opts.getConfigFile()));
        }
        // Initialize and start the agent
        AgentContext agentContext = new AgentContext(config);
        if (agentContext.flows().isEmpty()) {
            throw new ConfigurationException("There are no flows configured in configuration file.");
        }
        final Agent agent = new Agent(agentContext);

        // Make sure everything terminates cleanly when process is killed
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                if (!dontShutdownOnExit && agent.isRunning()) {
                    agent.stopAsync();
                    agent.awaitTerminated();
                }
            }
        });

        agent.startAsync();
        agent.awaitRunning();
        agent.awaitTerminated();
    } catch (Exception e) {
        logger.error("Unhandled error.", e);
        System.err.println("Unhandled error.");
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:xtrememp.XtremeMP.java

public static void main(String... args) throws Exception {
    // Load Settings
    Settings.loadSettings();//from   ww  w  .  j a  v a  2 s.co m
    // Configure logback
    Settings.configureLogback();

    // Enable uncaught exception catching.
    Thread.setDefaultUncaughtExceptionHandler((Thread t, Throwable e) -> {
        logger.error(t.getName(), e);
    });

    // Close error stream
    System.err.close();
    // First, look up for other instances running
    if (!MultipleInstancesHandler.getInstance().isFirstInstance()) {
        MultipleInstancesHandler.getInstance().sendArgumentsToFirstInstance(args);
    } else {
        // NORMAL APPLICATION STARTUP
        // Set language
        Locale locale = Utilities.getLanguages()[Settings.getLanguageIndex()];
        Locale.setDefault(locale);
        LanguageBundle.setLanguage(locale);

        // Animation configurations
        AnimationConfigurationManager.getInstance().disallowAnimations(AnimationFacet.ICON_GLOW, JTable.class);
        AnimationConfigurationManager.getInstance().disallowAnimations(AnimationFacet.ROLLOVER, JTable.class);
        AnimationConfigurationManager.getInstance().disallowAnimations(AnimationFacet.SELECTION, JTable.class);

        // Init
        getInstance().init(args);

        // Check for updates
        if (Settings.isAutomaticUpdatesEnabled()) {
            // wait 5 sec
            SoftwareUpdate.scheduleCheckForUpdates(5 * 1000);
        }
    }
}

From source file:Main.java

public static String getThreadName(Thread currentThread) {
    return currentThread.getName();
}

From source file:MyThread.java

static void showThreadStatus(Thread thrd) {
    System.out.println(thrd.getName() + " Alive:" + thrd.isAlive() + " State:" + thrd.getState());
}

From source file:Main.java

/**
 * Convention is to use class name of the class performing the task as thread name
 * @param threadName//  ww  w .j a  v a 2  s  .  c  o  m
 */
public static void interrupt(String threadName) {
    Enumeration e = threads.elements();
    while (e.hasMoreElements()) {
        Thread t = (Thread) e.nextElement();
        if (t.getName().equals(threadName)) {
            t.interrupt();
        }
    }
}

From source file:Main.java

public static String getThreadDesc(Thread thread) {
    return thread == null ? "pool-null-thread-null" : thread.getName();
    //        return thread == null ? "pool-null-thread-null" : thread.getName() + "-" + thread.getId();
}

From source file:Main.java

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

From source file:Main.java

/**
 * Wait for thread whose name contain the specified string to finish, i.e. to not appear in the
 * list of running threads any more.// w  w w .  j ava2  s  . co m
 *
 * @param name
 *
 * @throws InterruptedException
 * @author dominik.stadler
 */
public static void waitForThreadToFinishSubstring(final String name) throws InterruptedException {
    int count = Thread.currentThread().getThreadGroup().activeCount();

    Thread[] threads = new Thread[count];
    Thread.currentThread().getThreadGroup().enumerate(threads);

    for (Thread t : threads) {
        if (t != null && t.getName().contains(name)) {
            t.join();
        }
    }
}

From source file:Main.java

public static void printStatus(Object o) {
    if (o instanceof Thread) {
        Thread t = (Thread) o;
        System.out.println("Thread " + t.getName() + " " + t.getState());
    } else if (o instanceof ExecutorService) {
        ExecutorService e = (ExecutorService) o;
        System.out.println("Executor " + e.isShutdown() + " " + e.isTerminated());
    }//from ww w  . j  a v a2 s.c  o m
}