Example usage for java.lang Thread setDaemon

List of usage examples for java.lang Thread setDaemon

Introduction

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

Prototype

public final void setDaemon(boolean on) 

Source Link

Document

Marks this thread as either a #isDaemon daemon thread or a user thread.

Usage

From source file:com.emental.mindraider.core.search.SearchCommander.java

/**
 * Rebuild search index.//w  w  w. ja  v a  2 s. c  om
 */
public static void rebuildSearchAndTagIndices() {
    logger.debug(Messages.getString("SearchCommander.reindexing", MindRaider.profile.getNotebooksDirectory()));

    Thread thread = new Thread() {
        public void run() {
            try {
                SearchCommander.rebuild(MindRaider.profile.getNotebooksDirectory());
            } catch (IOException e) {
                logger.error(Messages.getString("SearchCommand.unableToRebuildSearchIndex"), e);
            }
        }
    };
    thread.setDaemon(true);
    thread.start();
}

From source file:it.crs4.pydoop.mapreduce.pipes.TaskLog.java

public static ScheduledExecutorService createLogSyncer() {
    final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override/* w  w w  .j  av a  2s  . c o m*/
        public Thread newThread(Runnable r) {
            final Thread t = Executors.defaultThreadFactory().newThread(r);
            t.setDaemon(true);
            t.setName("Thread for syncLogs");
            return t;
        }
    });
    ShutdownHookManager.get().addShutdownHook(new Runnable() {
        @Override
        public void run() {
            TaskLog.syncLogsShutdown(scheduler);
        }
    }, 50);
    scheduler.scheduleWithFixedDelay(new Runnable() {
        @Override
        public void run() {
            TaskLog.syncLogs();
        }
    }, 0L, 5L, TimeUnit.SECONDS);
    return scheduler;
}

From source file:com.igormaznitsa.sciareto.ui.UiUtils.java

public static void openInSystemViewer(@Nonnull final File file) {
    final Runnable startEdit = new Runnable() {
        @Override/*  w ww . j  av  a  2s. c  om*/
        public void run() {
            boolean ok = false;
            if (Desktop.isDesktopSupported()) {
                final Desktop dsk = Desktop.getDesktop();
                if (dsk.isSupported(Desktop.Action.OPEN)) {
                    try {
                        dsk.open(file);
                        ok = true;
                    } catch (Throwable ex) {
                        LOGGER.error("Can't open file in system viewer : " + file, ex);//NOI18N
                    }
                }
            }
            if (!ok) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        DialogProviderManager.getInstance().getDialogProvider()
                                .msgError("Can't open file in system viewer! See the log!");//NOI18N
                        Toolkit.getDefaultToolkit().beep();
                    }
                });
            }
        }
    };
    final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N
    thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread t, final Throwable e) {
            LOGGER.error("Detected uncaught exception in openInSystemViewer() for file " + file, e);
        }
    });

    thr.setDaemon(true);
    thr.start();
}

From source file:io.fabric8.maven.core.util.ProcessUtil.java

private static Thread startErrorLoggingThread(final Process process, final Logger log, final String commandDesc,
        final boolean useStandardLoggingLevel) {
    Thread logThread = new Thread("[ERR] " + commandDesc) {
        @Override//w w  w.ja  va  2  s .  com
        public void run() {
            try {
                processOutput(process.getErrorStream(), createErrorHandler(log, useStandardLoggingLevel));
            } catch (IOException e) {
                log.error("Failed to read error stream from %s : %s", commandDesc, e.getMessage());
            }
        }
    };
    logThread.setDaemon(true);
    logThread.start();
    return logThread;
}

From source file:io.fabric8.maven.core.util.ProcessUtil.java

private static Thread startOutputLoggingThread(final Process process, final Logger log,
        final String commandDesc, final boolean useStandardLoggingLevel) {
    Thread logThread = new Thread("[OUT] " + commandDesc) {
        @Override//from  w ww  .j  a  v a 2 s. co  m
        public void run() {
            try {
                processOutput(process.getInputStream(), createOutputHandler(log, useStandardLoggingLevel));
            } catch (IOException e) {
                log.error("Failed to read output stream from %s : %s", commandDesc, e.getMessage());
            }
        }
    };
    logThread.setDaemon(true);
    logThread.start();
    return logThread;
}

From source file:IOUtilities.java

/**
 * Loads data from the specified URLs asynchronously in a background thread.
 * Once all the data is loaded, it is passed to the specified
 * <code>DataReceiver</code>. <code>id</code> is a convenience allowing the
 * receiver to identify the data - it is merely passed back to the receiver.
 *//*from w w  w . j a  va 2s.c  om*/

public static void loadAsynchronously(URL[] urls, Object id, DataReceiver receiver, boolean allowCache) {
    Thread asyncReader = new Thread(new UrlDataReader((URL[]) urls.clone(), id, receiver, allowCache),
            "AsyncThread-" + (++UrlDataReader.threadCount));
    asyncReader.setDaemon(true);
    asyncReader.start();
}

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

public static void deleteFileAfterMinutes(final File file, final int minutes) {
    file.deleteOnExit();//w w w.  ja v  a 2s  . c om
    Thread t = new Thread() {
        @Override
        public void run() {
            try {
                Thread.sleep(minutes * 60000);
                FileUtils.deleteQuietly(file);
            } catch (InterruptedException ex) {
                LOG.trace(ex.getMessage());
            }
        }
    };
    t.setDaemon(true);
    t.start();
}

From source file:com.jhash.oimadmin.Utils.java

public static void executeAsyncOperation(String operationName, Runnable operation) {
    logger.debug("Setting up execution of {} in separate thread", operationName);
    Thread oimConnectionThread = threadFactory.newThread(new Runnable() {

        @Override//  ww  w  .  j  a v  a2s  . c o  m
        public void run() {
            try {
                logger.debug("Trying to run operation {}", operationName);
                operation.run();
                logger.debug("Completed operation {}.", operationName);
            } catch (Exception exception) {
                logger.warn("Failed to run operation " + operationName, exception);
            }
        }
    });
    oimConnectionThread.setDaemon(true);
    oimConnectionThread.setName(operationName);
    oimConnectionThread.start();
    logger.debug("Completed setup of execution of {} in separate thread", operationName);
}

From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java

public static void openInSystemViewer(@Nonnull final DialogProvider dialogProvider,
        @Nullable final VirtualFile theFile) {
    final File file = vfile2iofile(theFile);

    if (file == null) {
        LOGGER.error("Can't find file to open, null provided");
        dialogProvider.msgError("Can't find file to open");
    } else {/*from  ww  w .j  a v  a2s.com*/
        final Runnable startEdit = new Runnable() {
            @Override
            public void run() {
                boolean ok = false;
                if (Desktop.isDesktopSupported()) {
                    final Desktop dsk = Desktop.getDesktop();
                    if (dsk.isSupported(Desktop.Action.OPEN)) {
                        try {
                            dsk.open(file);
                            ok = true;
                        } catch (Throwable ex) {
                            LOGGER.error("Can't open file in system viewer : " + file, ex);//NOI18N
                        }
                    }
                }
                if (!ok) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dialogProvider.msgError("Can't open file in system viewer! See the log!");//NOI18N
                            Toolkit.getDefaultToolkit().beep();
                        }
                    });
                }
            }
        };
        final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N
        thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(final Thread t, final Throwable e) {
                LOGGER.error("Detected uncaught exception in openInSystemViewer() for file " + file, e);
            }
        });

        thr.setDaemon(true);
        thr.start();
    }
}

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

public static void waitForProcess(final Process process, final long timeout) throws InterruptedException {
    Thread t = new Thread() {
        @Override//from  w  ww. j  a  va 2 s .  com
        public void run() {
            try {
                Thread.sleep(timeout);
            } catch (InterruptedException ex) {
                LOG.warn(ex.getMessage());
            } finally {
                if (process != null) {
                    process.destroy();
                }
            }
        }
    };
    t.setDaemon(true);
    t.start();
    if (process != null) {
        int exitValue = process.waitFor();
        LOG.trace("process {} exits with {}", process, exitValue);
    }
}