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:JobScheduler.java

public JobScheduler(int poolSize) {
    tp = (poolSize > 0) ? new ThreadPool(poolSize) : null;
    Thread js = new Thread(this);
    js.setDaemon(true);
    js.start();// w  w  w  .ja  v a  2 s . co  m
}

From source file:net.sf.jasperreports.phantomjs.ProcessOutputReader.java

public void start() {
    //FIXME is two threads per process too much?  consider stream polling.
    OutputReader outputReader = new OutputReader();
    Thread outputThread = new Thread(outputReader, "JR PhantomJS output " + processId);
    outputThread.setDaemon(true);
    outputThread.start();// w  w w  .  ja va 2 s . c  o  m

    ErrorReader errorReader = new ErrorReader();
    Thread errorThread = new Thread(errorReader, "JR PhantomJS error " + processId);
    errorThread.setDaemon(true);
    errorThread.start();
}

From source file:com.hellblazer.jackal.configuration.ThreadConfig.java

@Bean(name = "agentDispatchers")
@Lazy/*from w w w  . ja va  2 s.  c  om*/
@Autowired
public ExecutorService agentDispatchers(Identity partitionIdentity) {
    final int id = partitionIdentity.id;
    return Executors.newCachedThreadPool(new ThreadFactory() {
        int count = 0;

        @Override
        public Thread newThread(Runnable target) {
            Thread t = new Thread(target, String.format("Agent Dispatcher[%s] for node[%s]", count++, id));
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error(String.format("Exception on %s", t), e);
                }
            });
            return t;
        }
    });
}

From source file:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileContentMonitor.java

public SdkCredentialsFileContentMonitor(File target, long pollingIntervalInMillis,
        FileAlterationListener listener) {

    _target = target;// w ww  .  ja  v a 2 s.  c  om

    // IllegalArgumentException is expected if target.getParentFile == null
    _observer = new FileAlterationObserver(target.getParentFile(), new FileFilter() {
        public boolean accept(File file) {
            return file.equals(_target);
        }
    });

    _monitor = new FileAlterationMonitor(pollingIntervalInMillis);
    _listener = listener;

    _observer.addListener(_listener);
    _monitor.addObserver(_observer);

    // Use daemon thread to avoid thread leakage
    _monitor.setThreadFactory(new ThreadFactory() {
        public Thread newThread(Runnable runnable) {
            Thread t = new Thread(runnable);
            t.setDaemon(true);
            t.setName("aws-credentials-file-monitor-thread");
            return t;
        }
    });
}

From source file:functionaltests.matlab.TestDisconnected.java

@Override
protected void runCommand(String testName, int nb_iter) throws Exception {
    ProcessBuilder pb = initCommand(testName, nb_iter);
    System.out.println("Running command : " + pb.command());

    File okFile = new File(mat_tb_home + fs + "ok.tst");
    File koFile = new File(mat_tb_home + fs + "ko.tst");
    File reFile = new File(mat_tb_home + fs + "re.tst");
    File startFile = new File(mat_tb_home + fs + "start.tst");

    if (okFile.exists()) {
        okFile.delete();//ww w .j a  v a2  s .c o  m
    }

    if (koFile.exists()) {
        koFile.delete();
    }
    if (reFile.exists()) {
        reFile.delete();
    }
    if (startFile.exists()) {
        startFile.delete();
    }

    Process p = pb.start();

    IOTools.LoggingThread lt1 = new IOTools.LoggingThread(p.getInputStream(),
            "[" + testName + "_" + index + "]", System.out);
    Thread t1 = new Thread(lt1, testName + "_" + index);
    t1.setDaemon(true);
    t1.start();

    int code = p.waitFor();
    while (!startFile.exists()) {
        Thread.sleep(100);
    }

    while (!okFile.exists() && !koFile.exists() && !reFile.exists()) {
        Thread.sleep(100);
    }

    if (logFile.exists()) {
        System.out.println(IOUtils.toString(logFile.toURI()));
    }

    if (index < nb_iter) {
        assertTrue(testName + "_" + index + " passed", !koFile.exists());
    } else {
        assertTrue(testName + " passed", okFile.exists());
    }

}

From source file:com.hellblazer.jackal.configuration.ThreadConfig.java

@Bean(name = "gossipDispatchers")
@Lazy//from   w  ww. jav a  2 s .  c  o m
@Autowired
public ExecutorService gossipDispatchers(Identity partitionIdentity) {
    final int id = partitionIdentity.id;
    return Executors.newCachedThreadPool(new ThreadFactory() {
        int count = 0;

        @Override
        public Thread newThread(Runnable target) {
            Thread t = new Thread(target, String.format("Gossip Dispatcher[%s] for node[%s]", count++, id));
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error(String.format("Exception on %s", t), e);
                }
            });
            return t;
        }
    });
}

From source file:httpscheduler.GenericRequestListenerThread.java

@Override
public void run() {
    System.out.println("Listening on port " + this.serversocket.getLocalPort());
    ArrayList<String> workerList = new ArrayList<>();

    // Read list of workers from configuration file
    try (BufferedReader br = new BufferedReader(new FileReader("./config/workers.conf"))) {
        for (String line; (line = br.readLine()) != null;) {
            workerList.add(line);/*from  www  .j a  va  2  s  .  c om*/
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(GenericRequestListenerThread.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(GenericRequestListenerThread.class.getName()).log(Level.SEVERE, null, ex);
    }

    // Initialize worker manager
    try {
        WorkerManager.useWorkerList(workerList);
    } catch (Exception ex) {
        Logger.getLogger(GenericRequestListenerThread.class.getName()).log(Level.SEVERE, null, ex);
        System.exit(-1);
    }
    //WorkerManager.printWorkerMap();

    Thread workerStatusThread = new UpdateWorkerStatusThread();
    workerStatusThread.start();
    System.out.println("ready for connections");
    while (!Thread.interrupted()) {
        try {
            // Set up HTTP connection
            Socket socket = this.serversocket.accept();
            HttpServerConnection conn = this.connFactory.createConnection(socket);

            // Initialize the pool
            Thread connectionHandler = new ConnectionHandlerThread(this.httpService, conn);
            connectionHandler.setDaemon(true);
            connectionHandlerExecutor.execute(connectionHandler);
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            System.err.println("I/O error initialising connection thread: " + e.getMessage());
            break;
        }
    }
    // when the listener is interupted shutdown the pool
    // and wait for any Connection Handler threads still running
    connectionHandlerExecutor.shutdown();
    while (!connectionHandlerExecutor.isTerminated()) {
    }

    System.out.println("Finished all connection handler threads");
}

From source file:com.frostwire.gui.library.LibraryUtils.java

public static void asyncAddToPlaylist(final Playlist playlist, final File[] files, final int index) {
    LibraryMediator.instance().getLibraryPlaylists().markBeginImport(playlist);
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                Set<File> ignore = TorrentUtil.getIgnorableFiles();
                addToPlaylist(playlist, files, false, index, ignore);
                playlist.save();/*  w ww  .  ja  v  a  2s . c o m*/
            } finally {
                asyncAddToPlaylistFinalizer(playlist);
            }
        }
    }, "asyncAddToPlaylist");
    t.setDaemon(true);
    t.start();
}

From source file:ca.wumbo.doommanager.client.controller.file.TaskManagerController.java

/**
 * Starts a new task with processing entries, and will pass the completed
 * object to the GUI for user access./*from   w ww .  j  ava2s  .  c o m*/
 * 
 * @param entryDesignator
 *       The EntryDesignator to run.
 * 
 * @throws NullPointerException
 *       If the argument is null.
 */
public void processEntryDesignation(EntryDesignator entryDesignator) {
    checkNotNull(entryDesignator, "Passed a null entry designator to the task manager.");

    // Set up the table information in the task manager.
    tableView.getItems().add(entryDesignator);

    // Start the thread.
    Thread t = new Thread(entryDesignator);
    t.setDaemon(true);
    t.start();
}

From source file:edu.gmu.isa681.server.Server.java

/**
 * Spawns a <code>SessionHandler</code> for the given SSL connection.
 * @param sslSocket//from w  w w.ja  va2s. c om
 */
private void handleRequest(SSLSocket sslSocket) {
    SessionHandler handler = new SessionHandler(sslSocket);
    Thread thread = new Thread(handler, "RequestHandler[" + sslSocket.getInetAddress().toString() + "]");
    thread.setDaemon(true);
    thread.start();
}