Example usage for java.lang Thread setPriority

List of usage examples for java.lang Thread setPriority

Introduction

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

Prototype

public final void setPriority(int newPriority) 

Source Link

Document

Changes the priority of this thread.

Usage

From source file:org.parosproxy.paros.extension.manualrequest.ManualRequestEditorDialog.java

protected void send(final Message aMessage) {
    final Thread t = new Thread(new Runnable() {
        @Override/*from   w  w  w  .  ja  va  2  s .co m*/
        public void run() {
            try {
                getMessageSender().handleSendMessage(aMessage);
                postSend();
            } catch (SSLException sslEx) {
                StringBuilder strBuilder = new StringBuilder();

                strBuilder.append(Constant.messages.getString("network.ssl.error.connect"));
                strBuilder.append(((HttpMessage) aMessage).getRequestHeader().getURI().toString()).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.exception"))
                        .append(sslEx.getMessage()).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.exception.rootcause"))
                        .append(ExceptionUtils.getRootCauseMessage(sslEx)).append('\n');
                strBuilder.append(Constant.messages.getString("network.ssl.error.help",
                        Constant.messages.getString("network.ssl.error.help.url")));
                logger.warn(strBuilder.toString());
                if (logger.isDebugEnabled()) {
                    logger.debug(sslEx, sslEx);
                }
                View.getSingleton().showWarningDialog(strBuilder.toString());
            } catch (Exception e) {
                logger.warn(e.getMessage(), e);
                View.getSingleton().showWarningDialog(e.getMessage());
            } finally {
                btnSend.setEnabled(true);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY);
    t.start();
}

From source file:com.alibaba.wasp.master.AssignmentManager.java

/**
 * Get a named {@link java.util.concurrent.ThreadFactory} that just builds daemon threads
 *
 * @param prefix/*from  ww w  .j av a  2  s.c o  m*/
 *          name prefix for all threads created from the factory
 * @return a thread factory that creates named, daemon threads
 */
private static ThreadFactory newDaemonThreadFactory(final String prefix) {
    final ThreadFactory namedFactory = Threads.getNamedThreadFactory(prefix);
    return new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = namedFactory.newThread(r);
            if (!t.isDaemon()) {
                t.setDaemon(true);
            }
            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }
            return t;
        }
    };
}

From source file:org.parosproxy.paros.model.Session.java

protected void open(final String sessionFile, final SessionListener callback) {
    Thread t = new Thread(new Runnable() {
        @Override/*from  w w  w  . j  ava2  s.  c  o  m*/
        public void run() {
            Exception thrownException = null;
            try {
                open(sessionFile);
            } catch (Exception e) {
                thrownException = e;
            }
            if (callback != null) {
                callback.sessionOpened(null, thrownException);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY - 2);
    t.start();
}

From source file:org.parosproxy.paros.model.Session.java

protected void open(final File file, final SessionListener callback) {
    Thread t = new Thread(new Runnable() {
        @Override//w w w . j a va  2  s . c  o  m
        public void run() {
            Exception thrownException = null;
            try {
                open(file.getAbsolutePath());
            } catch (Exception e) {
                thrownException = e;
            }
            if (callback != null) {
                callback.sessionOpened(file, thrownException);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY - 2);
    t.start();
}

From source file:com.adito.server.ServerLock.java

/**
 * Should be called when the service starts. This checks if a service is
 * already running, and if not creates the lock so future instances know.
 * /*from w  w  w  .java 2 s  .  co  m*/
 * @param port port the service is running on
 * @throws IOException
 */
public void start(int port) throws IOException {
    this.port = port;
    this.setup = ContextHolder.getContext().isSetupMode();

    /*
     * Check whether there is already a listener on the port, this means we
     * can throw a more meaningful exception than jetty does if a server
     * other than Adito is already running on this port
     */
    checkStatus();
    if (locked) {
        if (port == 443 || port == 8443) {
            throw new IOException("Some other server is already running on port " + port + "."
                    + "Most web servers will run on this port by default, so check if you have such "
                    + "a service is installed (IIS, Apache or Tomcat for example). Either shutdown "
                    + "and disable the conflicting server, or if you wish to run both services "
                    + "concurrently, change the port number on which one listens.");
        } else {
            throw new IOException("Some other server is already running on port " + port + "."
                    + "Check which other services you have enabled that may be causing "
                    + "this conflict. Then, either disable the service, change the port on "
                    + "which it is listening or change the port on which this server listens.");

        }
    }

    //
    PrintWriter pw = new PrintWriter(new FileOutputStream(lockFile));
    pw.println(ContextHolder.getContext().isSetupMode() + ":" + port);
    pw.flush();
    pw.close();
    started = true;

    lastLockChange = lockFile.lastModified();

    /* Start watching the lock file, if it disappears then shut down the
     * server
     */
    Thread t = new Thread("ServerLockMonitor") {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);
                    if (lastLockChange != lockFile.lastModified()) {
                        lastLockChange = lockFile.lastModified();
                        if (log.isDebugEnabled())
                            log.debug("Lock file changed, examining");
                        InputStream in = null;
                        try {
                            in = new FileInputStream(lockFile);
                            ;
                            BufferedReader br = new BufferedReader(new InputStreamReader(in));
                            String s = br.readLine();
                            Util.closeStream(in); // close so we can delete
                            if ("shutdown".equals(s)) {
                                ContextHolder.getContext().shutdown(false);
                                break;
                            } else if ("restart".equals(s)) {
                                ContextHolder.getContext().shutdown(true);
                                break;
                            }
                        } catch (IOException ioe) {
                            Util.closeStream(in);
                            throw ioe;
                        }
                    }
                } catch (Exception e) {
                }
            }
        }
    };
    t.setDaemon(true);
    t.setPriority(Thread.MIN_PRIORITY);
    t.start();

}

From source file:com.sslexplorer.server.ServerLock.java

/**
 * Should be called when the service starts. This checks if a service is
 * already running, and if not creates the lock so future instances know.
 * //from w  ww. j a  v  a 2 s.  co  m
 * @param port port the service is running on
 * @throws IOException
 */
public void start(int port) throws IOException {
    this.port = port;
    this.setup = ContextHolder.getContext().isSetupMode();

    /*
     * Check whether there is already a listener on the port, this means we
     * can throw a more meaningful exception than jetty does if a server
     * other than SSL-Explorer is already running on this port
     */
    checkStatus();
    if (locked) {
        if (port == 443 || port == 8443) {
            throw new IOException("Some other server is already running on port " + port + "."
                    + "Most web servers will run on this port by default, so check if you have such "
                    + "a service is installed (IIS, Apache or Tomcat for example). Either shutdown "
                    + "and disable the conflicting server, or if you wish to run both services "
                    + "concurrently, change the port number on which one listens.");
        } else {
            throw new IOException("Some other server is already running on port " + port + "."
                    + "Check which other services you have enabled that may be causing "
                    + "this conflict. Then, either disable the service, change the port on "
                    + "which it is listening or change the port on which this server listens.");

        }
    }

    //
    PrintWriter pw = new PrintWriter(new FileOutputStream(lockFile));
    pw.println(ContextHolder.getContext().isSetupMode() + ":" + port);
    pw.flush();
    pw.close();
    started = true;

    lastLockChange = lockFile.lastModified();

    /* Start watching the lock file, if it disappears then shut down the
     * server
     */
    Thread t = new Thread("ServerLockMonitor") {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);
                    if (lastLockChange != lockFile.lastModified()) {
                        lastLockChange = lockFile.lastModified();
                        if (log.isDebugEnabled())
                            log.debug("Lock file changed, examining");
                        InputStream in = null;
                        try {
                            in = new FileInputStream(lockFile);
                            ;
                            BufferedReader br = new BufferedReader(new InputStreamReader(in));
                            String s = br.readLine();
                            Util.closeStream(in); // close so we can delete
                            if ("shutdown".equals(s)) {
                                ContextHolder.getContext().shutdown(false);
                                break;
                            } else if ("restart".equals(s)) {
                                ContextHolder.getContext().shutdown(true);
                                break;
                            }
                        } catch (IOException ioe) {
                            Util.closeStream(in);
                            throw ioe;
                        }
                    }
                } catch (Exception e) {
                }
            }
        }
    };
    t.setDaemon(true);
    t.setPriority(Thread.MIN_PRIORITY);
    t.start();

}

From source file:org.parosproxy.paros.model.Session.java

/**
 * Asynchronous call to save a session.// w  ww.j  a  v  a 2  s .c om
 * @param fileName
 * @param callback
 */
protected void save(final String fileName, final SessionListener callback) {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            Exception thrownException = null;
            try {
                save(fileName);
            } catch (Exception e) {
                // ZAP: Log exceptions
                log.warn(e.getMessage(), e);
                thrownException = e;
            }
            if (callback != null) {
                callback.sessionSaved(thrownException);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY - 2);
    t.start();
}

From source file:org.parosproxy.paros.extension.history.ManualRequestEditorDialog.java

private void send(final HttpMessage msg) {
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                getHttpSender().sendAndReceive(msg, getChkFollowRedirect().isSelected());

                EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        if (!msg.getResponseHeader().isEmpty()) {
                            getResponsePanel().setMessage(msg, false);

                            final int finalType = HistoryReference.TYPE_MANUAL;
                            Thread t = new Thread(new Runnable() {
                                public void run() {
                                    addHistory(msg, finalType);
                                }//from ww  w.java  2 s .co  m
                            });
                            t.start();

                        }
                        getPanelTab().setSelectedIndex(1);
                    }
                });

            } catch (NullPointerException npe) {
                getExtention().getView().showWarningDialog("Malformed header error.");
            } catch (HttpMalformedHeaderException mhe) {
                getExtention().getView().showWarningDialog("Malformed header error.");
            } catch (IOException ioe) {
                getExtention().getView().showWarningDialog("IO error in sending request.");
            } catch (Exception e) {
                // ZAP: Log exceptions
                log.warn(e.getMessage(), e);
            } finally {
                btnSend.setEnabled(true);
            }
        }
    });

    t.setPriority(Thread.NORM_PRIORITY);
    t.start();
}

From source file:org.parosproxy.paros.model.Session.java

/**
 * Asynchronous call to snapshot a session.
 * @param fileName/*w w w .ja va2s.c om*/
 * @param callback
 */
protected void snapshot(final String fileName, final SessionListener callback) {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            Exception thrownException = null;
            try {
                snapshot(fileName);
            } catch (Exception e) {
                // ZAP: Log exceptions
                log.warn(e.getMessage(), e);
                thrownException = e;
            }
            if (callback != null) {
                callback.sessionSnapshot(thrownException);
            }
        }
    });
    t.setPriority(Thread.NORM_PRIORITY - 2);
    t.start();
}

From source file:net.sf.profiler4j.console.util.task.LongTaskExecutorDialog.java

public void runTask(final LongTask task) {
    label.setText("Executing long-running task...");
    task.setDialog(this);
    Thread t = new Thread("PROFILER4J_TASK") {
        public void run() {
            log.debug("TASK STARTED");
            try {
                task.executeInBackground();
            } catch (final Exception e) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        log.error("Caught task error", e);
                        error = e;//from  w  w w .  j  a v  a 2s.  c  o  m
                    };
                });
            } finally {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        log.debug("TASK COMPLETED");
                        if (error != null) {
                            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                            progressBar.setIndeterminate(false);
                            setSize(486, 379);
                            setVisible(true);
                            toFront();
                            ((JComponent) statusTextArea.getParent()).revalidate();
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            error.printStackTrace(pw);
                            statusTextArea.setText(sw.toString());
                            statusTextArea.setCaretPosition(0);
                            task.setError(error);
                        } else {
                            setVisible(false);
                            dispose();
                        }
                    }
                });
            }
        };
    };
    t.setName("LongTaskRunner");
    t.setPriority(Thread.MIN_PRIORITY);
    t.setDaemon(false);
    t.start();

    setLocation(getLocation().x, getLocation().y - 120);
    setVisible(true);
}