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.frostwire.gui.library.LibraryUtils.java

public static void asyncAddRadioStation(final String url) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            addRadioStation(url);/* w  ww .  j  ava  2s.com*/
        }
    }, "ImportRadioStation");
    t.setDaemon(true);
    t.start();
}

From source file:examples.IOUtil.java

public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput,
        final InputStream localInput, final OutputStream localOutput) {
    Thread reader, writer;

    reader = new Thread() {
        public void run() {
            int ch;

            try {
                while (!interrupted() && (ch = localInput.read()) != -1) {
                    remoteOutput.write(ch);
                    remoteOutput.flush();
                }/*ww  w  .  j  a v  a2 s. c  o m*/
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    };

    writer = new Thread() {
        public void run() {
            try {
                Util.copyStream(remoteInput, localOutput);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    };

    writer.setPriority(Thread.currentThread().getPriority() + 1);

    writer.start();
    reader.setDaemon(true);
    reader.start();

    try {
        writer.join();
        reader.interrupt();
    } catch (InterruptedException e) {
    }
}

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

public static void waitForOutputLine(final Process process, String lineExpected, final long timeout)
        throws IOException {
    Thread t = new Thread() {
        @Override/*  w  ww  .  j a  v  a2  s  .  c o m*/
        public void run() {
            try {
                Thread.sleep(timeout);
            } catch (InterruptedException ex) {
                LOG.warn(ex.getMessage());
            } finally {
                if (process != null) {
                    process.destroy();
                }
            }
        }
    };
    t.setName(Thread.currentThread().getName() + "-" + t.hashCode());
    t.setDaemon(true);
    t.start();

    try (BufferedReader stdIn = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
        for (String line = stdIn.readLine(); line != null;) {
            if (line.contains(lineExpected)) {
                break;
            }
            line = stdIn.readLine();
        }
    }
    t.interrupt();
}

From source file:com.hkd.socketclient.IOUtil.java

public static final void readWrite(final InputStream remoteInput, final OutputStream remoteOutput,
        final InputStream localInput, final OutputStream localOutput) {
    Thread reader, writer;

    reader = new Thread() {
        @Override/*from   w w w  . j a va  2 s .  c om*/
        public void run() {
            int ch;

            try {
                while (!interrupted() && (ch = localInput.read()) != -1) {
                    remoteOutput.write(ch);
                    remoteOutput.flush();
                }
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
    };

    writer = new Thread() {
        @Override
        public void run() {
            try {
                Util.copyStream(remoteInput, localOutput);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    };

    writer.setPriority(Thread.currentThread().getPriority() + 1);

    writer.start();
    reader.setDaemon(true);
    reader.start();

    try {
        writer.join();
        reader.interrupt();
    } catch (InterruptedException e) {
    }
}

From source file:Main.java

public TestPane() {
    Thread thread = new Thread(new BackgroundMonitor());
    thread.setDaemon(true);
    thread.start();
}

From source file:DaemonLock.java

public synchronized void acquire() {
    if (lockCount++ == 0) {
        Thread t = new Thread(this);
        t.setDaemon(false);
        t.start();/*from  ww  w.j  a v  a  2  s. com*/
    }
}

From source file:DaemonThreadFactory.java

/**
 * Create a new thread for the thread pool.  The create
 * thread will be a daemon thread.//from w ww .  j a  v  a2 s.  com
 * 
 * @param r      The runnable used by the thread pool.
 * 
 * @return The newly created thread. 
 */
public Thread newThread(Runnable r) {
    Thread t = factory.newThread(r);
    if (!t.isDaemon()) {
        t.setDaemon(true);
    }
    return t;
}

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

public static void createNewPlaylist(final List<? extends AbstractLibraryTableDataLine<?>> lines) {
    String playlistName = (String) JOptionPane.showInputDialog(GUIMediator.getAppFrame(),
            I18n.tr("Playlist name"), I18n.tr("Playlist name"), JOptionPane.PLAIN_MESSAGE, null, null,
            calculateName(lines));//w  ww  .j  a  v a 2  s . c o  m

    if (playlistName != null && playlistName.length() > 0) {
        final Playlist playlist = LibraryMediator.getLibrary().newPlaylist(playlistName, playlistName);
        playlist.save();
        LibraryMediator.instance().getLibraryPlaylists().addPlaylist(playlist);
        LibraryMediator.instance().getLibraryPlaylists().markBeginImport(playlist);
        Thread t = new Thread(new Runnable() {
            public void run() {
                addToPlaylist(playlist, lines);
                playlist.save();
                asyncAddToPlaylistFinalizer(playlist);
            }
        }, "createNewPlaylist");
        t.setDaemon(true);
        t.start();
    }
}

From source file:io.kahu.hawaii.util.call.dispatch.HawaiiThreadFactory.java

@Override
public Thread newThread(Runnable r) {
    synchronized (this) {
        nrThreads++;/*from w w  w .  j  a v a2  s .c  o  m*/
    }
    Thread t = new Thread(r, threadPrefix + "-" + nrThreads);
    t.setDaemon(true);
    return t;
}

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

public static void asyncAddToPlaylist(final Playlist playlist,
        final List<? extends AbstractLibraryTableDataLine<?>> lines) {
    LibraryMediator.instance().getLibraryPlaylists().markBeginImport(playlist);
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                addToPlaylist(playlist, lines);
            } finally {
                asyncAddToPlaylistFinalizer(playlist);
            }//  ww w  . java  2 s  .c o m
        }
    }, "asyncAddToPlaylist");
    t.setDaemon(true);
    t.start();
}