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:de.teambluebaer.patientix.helper.RestfulHelper.java

/**
 * Method which executes a request to the server.
 * It must be a new Thread to send the data, otherwise u'll get an NetworkAuthentication-Error
 * The join operation simulates a wait for main-thread, otherwise, the main will run up
 *
 * @param method       Is the End of the URL at which the request will be send
 * @param parameterMap ArrayList with parameters for the request
 * @return int of the responseCode//  w w w.  j a v a  2  s.  co m
 */
public int executeRequest(final String method, final ArrayList<NameValuePair> parameterMap) {

    Thread networkThread = new Thread() {
        public void run() {

            setURLForRequest(method);
            postDataToServer(method, parameterMap);
        }
    };
    try {
        networkThread.setDaemon(false);
        networkThread.start();
        //Join main-thread with Network-Thread to share Domain-Objects
        // The network-thread get an Timeout of 1 Second, otherwise, the application will hang
        networkThread.join(Constants.PING - 1);
        try {
            sleep(Constants.PING);
        } catch (Exception e) {
            Log.d("SleepExeption", e.toString());
        }
    } catch (InterruptedException e) {
        return 503;
    }
    return responseCode;
}

From source file:com.likya.myra.jef.controller.BaseSchedulerController.java

protected void executeJob(JobImpl scheduledJob) throws InterruptedException {

    if (inDangerGroupZoneIntrusion(scheduledJob)) {
        CoreFactory.getLogger().debug("Tehlikeli Grup kst nedeni ile almyor ! ==> "
                + scheduledJob.getAbstractJobType().getId());
        return;//from   ww w.jav  a  2 s  . c om
    }

    //      if (getScenarioRuntimeProperties().getCurrentState() == ScenarioRuntimeProperties.STATE_WAITING) {
    //         getScenarioRuntimeProperties().setCurrentState(ScenarioRuntimeProperties.STATE_RUNNING);
    //         getScenarioRuntimeProperties().setStartTime(Calendar.getInstance().getTime());
    //      }

    ChangeLSI.forValue(scheduledJob.getAbstractJobType(), StateName.RUNNING, SubstateName.STAGE_IN);

    CoreFactory.getLogger().debug(CoreFactory.getMessage("Myra.66"));

    Thread starterThread = new Thread(scheduledJob);

    scheduledJob.setMyExecuter(starterThread);
    starterThread.setDaemon(true);

    scheduledJob.getMyExecuter().start();

    return;
}

From source file:net.sbbi.upnp.ServicesEventing.java

private void startServicesEventingThread() {
    synchronized (singleton) {
        if (!inService) {
            Thread deamon = new Thread(singleton, "ServicesEventing daemon");
            deamon.setDaemon(daemon);
            inService = true;//ww  w  .j  a v  a2 s. c o m
            deamon.start();
        }
    }
}

From source file:de.thomasbolz.renamer.RenamerGUI.java

/**
 * Action handler for the rename button//w  w w .  ja v a 2 s .  co m
 *
 * @param event
 */
@FXML
void rename(ActionEvent event) {
    if (!checkDirectories(getSrcDirectory(), getTargetDirectory())) {
        return;
    }
    if (isSimulationMode()) {
        txtOut.clear();
        btnRename.setDisable(true);
        renamer = new Renamer(getSrcDirectory().toPath(), getTargetDirectory().toPath());
        FileTreeAnalysisTask task = new FileTreeAnalysisTask(renamer);
        task.messageProperty()
                .addListener((observableValue, s, s2) -> txtOut.appendText(task.getMessage() + "\n"));
        EventHandler<WorkerStateEvent> enableButtonRename = (workerStateEvent) -> btnRename.setDisable(false);
        task.setOnSucceeded(enableButtonRename);
        task.setOnFailed(enableButtonRename);
        //            progressDirs.progressProperty().bind(task.progressProperty());
        new Thread(task).start();
        //            Runnable myTask = new Runnable() {
        //                @Override
        //                public void run() {
        //                    renamer = new Renamer(getSrcDirectory().toPath(), getTargetDirectory().toPath());
        ////                    renamer.addProgressListener(RenamerGUI.this);
        //                    renamer.prepareCopyTasks();
        //                    final SortedMap<Path, List<CopyTask>> copyTasks = renamer.getCopyTasks();
        //                    StringBuilder sb = new StringBuilder();
        //                    copyTasks.forEach((path, tasks) -> {
        //                        sb.append(path);
        //                        sb.append("\n");
        //                        tasks.forEach(task -> {
        //                            sb.append(task.toFormattedString());
        //                            sb.append("\n");
        //                        });
        //                    });
        //                    Platform.runLater(new Runnable() {
        //                        @Override
        //                        public void run() {
        //                            txtOut.setText(sb.toString());
        //                        }
        //                    });
        //                }
        //            };
        //            final Thread taskRunner = new Thread(myTask);
        //        taskRunner.setName("TaskRunner");
        //        taskRunner.setDaemon(true);
        //            taskRunner.start();

        setSimulationMode(false);
    } else {
        //            Action confirm = Dialogs.create()
        //                    .title("Confirm renaming")
        //                    .masthead("Do you want to execute the renaming?")
        //                    .message("The author of this software is not liable for any damage that might occur to your files.")
        //                    .showConfirm();
        //
        //            if (confirm == Dialog.Actions.YES) {
        txtOut.clear();
        btnRename.setDisable(true);
        ExecuteCopyTask task = new ExecuteCopyTask(renamer);
        EventHandler<WorkerStateEvent> enableButtonRename = (workerStateEvent) -> btnRename.setDisable(false);
        task.setOnSucceeded(enableButtonRename);
        task.setOnFailed(enableButtonRename);
        progressDirs.progressProperty().bind(task.dirProgressProperty());
        progressFiles.progressProperty().bind(task.fileProgressProperty());
        task.progressMessageProperty()
                .addListener((observableValue, s, s2) -> Platform.runLater(() -> txtOut.appendText(s2)));

        Thread th = new Thread(task);
        th.setDaemon(true);
        th.start();
        setSimulationMode(true);
    }

}

From source file:Model.CacheInMemory.java

public CacheInMemory(long timeToLive, final long timerInterval, int maxItems) {
    this.timeToLive = timeToLive * 1000;

    cacheMap = new LRUMap(maxItems);

    if (timeToLive > 0 && timerInterval > 0) {

        Thread t = new Thread(new Runnable() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(timerInterval * 1000);
                    } catch (InterruptedException ex) {
                    }//  w  ww .ja v a  2  s  .  c o m
                    cleanup();
                }
            }
        });

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

From source file:com.googlecode.shutdownlistener.ShutdownHandler.java

public final void start() throws Exception {
    final ShutdownConfiguration config = ShutdownConfiguration.getInstance();

    final ShutdownSocketListener shutdownSocketListener = new ShutdownSocketListener(config.getHost(),
            config.getPort());//from  w w w.  j a va2 s  . com

    final Thread shutdownSocketThread = new Thread(shutdownSocketListener,
            "ShutdownListener-" + config.getHost() + ":" + config.getPort());
    shutdownSocketThread.setDaemon(true);
    shutdownSocketThread.start();

    //Add the listener to the shutdown list 
    this.internalShutdownListeners.add(shutdownSocketListener);

    //Register a shutdown handler
    final Thread shutdownHook = new Thread(new ShutdownHookHandler(), "JVM Shutdown Hook");
    Runtime.getRuntime().addShutdownHook(shutdownHook);
    this.logger.debug("Registered JVM shutdown hook");

    this.internalShutdownListeners.add(new ShutdownListener() {
        public void shutdown() {
            Runtime.getRuntime().removeShutdownHook(shutdownHook);
            logger.debug("Removed JVM shutdown hook");
        }

        @Override
        public String toString() {
            return "JVM Shutdown Hook Remover";
        }
    });
}

From source file:com.gargoylesoftware.htmlunit.ThreadedRefreshHandler.java

/**
 * Refreshes the specified page using the specified URL after the specified number
 * of seconds./*from  w ww . j  a  va 2s.  co  m*/
 * @param page the page that is going to be refreshed
 * @param url the URL where the new page will be loaded
 * @param seconds the number of seconds to wait before reloading the page
 */
@Override
public void handleRefresh(final Page page, final URL url, final int seconds) {
    final Thread thread = new Thread("ThreadedRefreshHandler Thread") {
        @Override
        public void run() {
            try {
                new WaitingRefreshHandler().handleRefresh(page, url, seconds);
            } catch (final IOException e) {
                LOG.error("Unable to refresh page!", e);
                throw new RuntimeException("Unable to refresh page!", e);
            }
        }
    };
    thread.setDaemon(true);
    thread.start();
}

From source file:com.igormaznitsa.sciareto.metrics.MetricsService.java

public void sendStatistics() {
    if (this.enabled.get()) {
        LOGGER.info("Starting statistics send");
        final Thread thread = new Thread(new Runnable() {
            @Override//  w  ww  . jav a  2  s  . com
            public void run() {
                try {
                    doAction();
                } catch (Exception ex) {
                    LOGGER.error("Can't send statistics", ex);
                }
            }
        }, "SCIARETO_STATISTIC_SEND");
        thread.setDaemon(true);
        thread.start();
    } else {
        LOGGER.info("Ignored statistics because disabled");
    }
}

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

/**
 * Async//  w w  w.  j  a  v  a 2s.c  o  m
 * @param file
 */
public void setFile(final File file) {
    if (this.file != null && file != null && this.file.equals(file)) {
        return;
    }
    this.file = file;
    Thread t = new Thread(new Runnable() {
        public void run() {
            Image image = retrieveImage(file);
            if (file != null && file.equals(LibraryCoverArt.this.file)) {
                setPrivateImage(image);
            }
        }
    }, "Cover Art extract");
    t.setDaemon(true);
    t.start();
}

From source file:com.nesscomputing.syslog4j.impl.AbstractSyslog.java

public Thread createWriterThread(AbstractSyslogWriter syslogWriter) {
    Thread newWriterThread = new Thread(syslogWriter);
    newWriterThread.setName("SyslogWriter: " + getProtocol());
    newWriterThread.setDaemon(syslogConfig.isUseDaemonThread());
    if (syslogConfig.getThreadPriority() > -1) {
        newWriterThread.setPriority(syslogConfig.getThreadPriority());
    }/*from   w ww  .ja v  a2 s  .  c om*/
    syslogWriter.setThread(newWriterThread);
    newWriterThread.start();

    return newWriterThread;
}