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:maker.task.compile.ReplTestPumpStreamHandler.java

/**
 * Creates a stream pumper to copy the given input stream to the given
 * output stream.//from   www.ja  v  a  2  s  . com
 *
 * @param is the System.in input stream to copy from
 * @param os the output stream to copy into
 * @return the stream pumper thread
 */
private Thread createSystemInPump(final InputStream is, final OutputStream os) {
    inputStreamPumper = new InputStreamPumper(is, os);
    final Thread result = new Thread(inputStreamPumper, "Exec Input Stream Pumper");
    result.setDaemon(true);
    return result;
}

From source file:gov.va.isaac.mojos.profileSync.ProfilesMojoBase.java

protected String getPassword() throws MojoExecutionException {
    if (password == null) {
        password = System.getProperty(PROFILE_SYNC_PASSWORD_PROPERTY);

        //still blank, try the passed in param
        if (StringUtils.isBlank(password)) {
            password = profileSyncPassword;
        }/*from   ww w.  ja  v  a 2s.  c om*/

        //still no password, prompt if allowed
        if (StringUtils.isBlank(password) && !Boolean.getBoolean(PROFILE_SYNC_NO_PROMPTS)) {
            Callable<Void> callable = new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    try {
                        if (!disableHintGiven) {
                            System.out.println("To disable remote sync during build, add '-D"
                                    + PROFILE_SYNC_DISABLE + "=true' to your maven command");
                            disableHintGiven = true;
                        }
                        System.out.println("Enter the " + config_.getChangeSetUrlType().name()
                                + " password for the Profiles/Changset remote store: ("
                                + config_.getChangeSetUrl() + "):");

                        //Use console if available, for password masking
                        Console console = System.console();
                        if (console != null) {
                            password = new String(console.readPassword());
                        } else {
                            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                            password = br.readLine();
                        }
                    } catch (IOException e) {
                        throw new MojoExecutionException("Error reading password from console");
                    }
                    return null;
                }
            };

            try {
                Executors.newSingleThreadExecutor(new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        Thread t = new Thread(r, "User Password Prompt Thread");
                        t.setDaemon(true);
                        return t;
                    }
                }).submit(callable).get(2, TimeUnit.MINUTES);
            } catch (TimeoutException | InterruptedException e) {
                throw new MojoExecutionException("Password not provided within timeout");
            } catch (ExecutionException ee) {
                throw (ee.getCause() instanceof MojoExecutionException ? (MojoExecutionException) ee.getCause()
                        : new MojoExecutionException("Unexpected", ee.getCause()));
            }
        }
    }
    return password;
}

From source file:de.xwic.appkit.core.cluster.impl.Cluster.java

/**
 * Internal initialization//from ww w  .j av  a2  s.co m
 */
public void initInternal() {

    inbConHandler = new InboundConnectionHandler(this, config.getPortNumber());
    Thread tConHandler = new Thread(inbConHandler, "InboundConnectionHandler");
    tConHandler.setDaemon(true);
    tConHandler.start();

    for (NodeAddress na : config.getKnownNodes()) {
        registerNode(na);
    }

    // initiate the NodeController
    Thread tNC = new Thread(new NodeController(this), "NodeController");
    tNC.setDaemon(true);
    tNC.start();

    tEventQueue = new Thread(new EventQueueController(this), "EventQueueController");
    tEventQueue.setDaemon(true);
    tEventQueue.start();

}

From source file:com.ejisto.event.ApplicationEventDispatcher.java

public ApplicationEventDispatcher(TaskManager taskManager) {
    this.registeredListeners = new ConcurrentHashMap<>();
    this.taskManager = taskManager;
    this.running = true;
    Thread t = new Thread(() -> {
        try {//from w w  w . jav  a2 s.co m
            processPendingEvents();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException(e);
        }
    }, "applicationEventDispatcher");
    t.setDaemon(true);
    t.start();
}

From source file:maker.task.compile.ReplTestPumpStreamHandler.java

/**
 * Creates a stream pumper to copy the given input stream to the given
 * output stream./* w  w w  . j  a va2 s . c om*/
 *
 * @param is                 the input stream to copy from
 * @param os                 the output stream to copy into
 * @param closeWhenExhausted close the output stream when the input stream is exhausted
 * @return the stream pumper thread
 */
protected Thread createPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
    final Thread result = new Thread(new StreamPumper(is, os, closeWhenExhausted), "Exec Stream Pumper");
    result.setDaemon(true);
    return result;
}

From source file:org.dawnsci.commandserver.core.process.ProgressableProcess.java

/**
 * Call to start the process and broadcast status
 * updates. Subclasses may redefine what is done
 * on the start method, by default a thread is started
 * in daemon mode to run things./*from w  ww  .java2 s. c  om*/
 */
public void start() {

    if (isBlocking()) {
        run(); // Block until process has run.
    } else {
        final Thread thread = new Thread(this);
        thread.setDaemon(true);
        thread.setPriority(Thread.MAX_PRIORITY);
        thread.start();
    }
}

From source file:com.google.devtools.build.lib.bazel.dash.DashModule.java

public DashModule() {
    // Make sure sender != null before we hop on the event bus.
    sender = NO_OP_SENDER;/*from ww w. j  a  va2 s. c om*/
    executorService = Executors.newFixedThreadPool(5, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable runnable) {
            Thread thread = Executors.defaultThreadFactory().newThread(runnable);
            thread.setDaemon(true);
            return thread;
        }
    });
}

From source file:com.streamsets.datacollector.restapi.AdminResource.java

@POST
@Path("/shutdown")
@ApiOperation(value = "Shutdown SDC", authorizations = @Authorization(value = "basic"))
@Produces(MediaType.APPLICATION_JSON)//w w  w .  ja  v a 2 s  . c o  m
@RolesAllowed({ AuthzRole.ADMIN, AuthzRole.ADMIN_REMOTE })
public Response shutdown() throws PipelineStoreException {
    Thread thread = new Thread("Shutdown Request") {
        @Override
        public void run() {
            // sleeping  500ms to allow the HTTP response to go back
            ThreadUtil.sleep(500);
            runtimeInfo.shutdown(0);
        }
    };
    thread.setDaemon(true);
    thread.start();
    return Response.ok().build();
}

From source file:com.streamsets.datacollector.restapi.AdminResource.java

@POST
@Path("/restart")
@ApiOperation(value = "Restart SDC", authorizations = @Authorization(value = "basic"))
@Produces(MediaType.APPLICATION_JSON)/*from  w  w  w  . j a va2s.c  om*/
@RolesAllowed({ AuthzRole.ADMIN, AuthzRole.ADMIN_REMOTE })
public Response restart() throws PipelineStoreException {
    Thread thread = new Thread("Shutdown Request") {
        @Override
        public void run() {
            // sleeping  500ms to allow the HTTP response to go back
            ThreadUtil.sleep(500);
            runtimeInfo.shutdown(88);
        }
    };
    thread.setDaemon(true);
    thread.start();
    return Response.ok().build();
}

From source file:com.netflix.zeno.diff.TypeDiffOperation.java

@SuppressWarnings("unchecked")
public TypeDiff<T> performDiff(DiffSerializationFramework framework, Iterable<T> fromState, Iterable<T> toState,
        int numThreads) {
    Map<Object, T> fromStateObjects = new HashMap<Object, T>();

    for (T obj : fromState) {
        fromStateObjects.put(instruction.getKey(obj), obj);
    }//  www  .j a v  a2  s .c o m

    ArrayList<List<T>> perProcessorWorkList = new ArrayList<List<T>>(numThreads); // each entry is a job
    for (int i = 0; i < numThreads; ++i) {
        perProcessorWorkList.add(new ArrayList<T>());
    }

    Map<Object, Object> toStateKeys = new ConcurrentHashMap<Object, Object>();

    int toIncrCount = 0;
    for (T toObject : toState) {
        perProcessorWorkList.get(toIncrCount % numThreads).add(toObject);
        toIncrCount++;
    }

    ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            final Thread thread = new Thread(r, "TypeDiff_" + instruction.getTypeIdentifier());
            thread.setDaemon(true);
            return thread;
        }
    });

    try {
        ArrayList<Future<TypeDiff<T>>> workResultList = new ArrayList<Future<TypeDiff<T>>>(
                perProcessorWorkList.size());
        for (final List<T> workList : perProcessorWorkList) {
            if (workList != null && !workList.isEmpty()) {
                workResultList.add(executor.submit(new TypeDiffCallable<T>(framework, instruction,
                        fromStateObjects, toStateKeys, workList)));
            }
        }

        TypeDiff<T> mergedDiff = new TypeDiff<T>(instruction.getTypeIdentifier());
        for (final Future<TypeDiff<T>> future : workResultList) {
            try {
                TypeDiff<T> typeDiff = future.get();
                mergeTypeDiff(mergedDiff, typeDiff);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        for (Map.Entry<Object, T> entry : fromStateObjects.entrySet()) {
            mergedDiff.incrementFrom();
            if (!toStateKeys.containsKey(entry.getKey()))
                mergedDiff.addExtraInFrom(entry.getValue());
        }

        return mergedDiff;

    } finally {
        executor.shutdownNow();
    }
}