Example usage for java.lang Thread MAX_PRIORITY

List of usage examples for java.lang Thread MAX_PRIORITY

Introduction

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

Prototype

int MAX_PRIORITY

To view the source code for java.lang Thread MAX_PRIORITY.

Click Source Link

Document

The maximum priority that a thread can have.

Usage

From source file:org.batoo.jpa.benchmark.BenchmarkTest.java

/**
 * // ww w  .  j av a  2  s  . c om
 * @since 2.0.0
 */
@Before
public void measureBefore() {
    this.profilingQueue = Lists.newArrayList();

    final Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            BenchmarkTest.this.measureTimes(BenchmarkTest.this.profilingQueue);
        }
    }, "Profiler");

    t.setDaemon(true);
    t.setPriority(Thread.MAX_PRIORITY);
    t.start();
}

From source file:org.apache.cocoon.thread.impl.DefaultRunnableManager.java

/**
 * DOCUMENT ME!/*from w ww  . j a  v  a  2s.co  m*/
 *
 * @param priority
 *            The priority to set as string value.
 *
 * @return The priority as int value.
 */
private int convertPriority(final String priority) {
    if ("MIN".equalsIgnoreCase(priority)) {
        return Thread.MIN_PRIORITY;
    } else if ("NORM".equalsIgnoreCase(priority)) {
        return Thread.NORM_PRIORITY;
    } else if ("MAX".equalsIgnoreCase(priority)) {
        return Thread.MAX_PRIORITY;
    } else {
        getLogger().warn("Unknown thread priority \"" + priority + "\". Set to \"NORM\".");

        return Thread.NORM_PRIORITY;
    }
}

From source file:com.heliosapm.tsdblite.metric.MetricCache.java

private MetricCache() {

    final String jmxDomain = ConfigurationHelper.getSystemThenEnvProperty(Constants.CONF_METRICS_MSERVER,
            Constants.DEFAULT_METRICS_MSERVER);
    if (!JMXHelper.getHeliosMBeanServer().getDefaultDomain().equals(jmxDomain)) {
        metricMBeanServer = JMXHelper.createMBeanServer(jmxDomain, true);
        final int port = ConfigurationHelper.getIntSystemThenEnvProperty(Constants.CONF_METRICS_JMXMP_PORT,
                Constants.DEFAULT_METRICS_JMXMP_PORT);
        if (port > -1) {
            final String iface = ConfigurationHelper.getSystemThenEnvProperty(
                    Constants.CONF_METRICS_JMXMP_IFACE, Constants.DEFAULT_METRICS_JMXMP_IFACE);
            final JMXServiceURL surl = JMXHelper.fireUpJMXMPServer(iface, port, metricMBeanServer);
            log.info("Metrics MBeanServer [{}] available at [{}]", jmxDomain, surl);
        }//from  ww w  .j  a  va 2 s  .c  o  m
    } else {
        metricMBeanServer = JMXHelper.getHeliosMBeanServer();
    }
    expiry = ConfigurationHelper.getLongSystemThenEnvProperty(Constants.CONF_METRIC_EXPIRY,
            Constants.DEFAULT_METRIC_EXPIRY);
    expiryPeriod = ConfigurationHelper.getLongSystemThenEnvProperty(Constants.CONF_METRIC_EXPIRY_PERIOD,
            Constants.DEFAULT_METRIC_EXPIRY_PERIOD);
    expiryThread = new Thread(new Runnable() {
        @Override
        public void run() {
            while (true) {
                final AtomicInteger expiredMetricCount = new AtomicInteger(0);
                SystemClock.sleep(expiryPeriod);
                final long startTime = System.currentTimeMillis();
                final ObjectName[] metricObjectNames = JMXHelper.query(JMXHelper.ALL_MBEANS_FILTER,
                        metricBeanQuery);
                final Collection<Future<?>> taskFutures = new ArrayList<Future<?>>(metricObjectNames.length);
                for (final ObjectName on : metricObjectNames) {
                    taskFutures.add(expiryService.submit(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                final long now = System.currentTimeMillis();
                                final Map<String, Object> attrMap = JMXHelper.getAttributes(on,
                                        EXPIRY_ATTRIBUTES);
                                if (!attrMap.containsKey("LastActivity")) {
                                    log.warn("No LA for [{}], AttrMap: {}", on, attrMap);
                                    return;
                                }
                                final long lastActivity = (Long) attrMap.get("LastActivity");
                                final long age = now - lastActivity;
                                if (age > expiry) {
                                    expiredMetricCount.incrementAndGet();
                                    metricMBeanServer.unregisterMBean(on);
                                    expiredMetrics.increment();
                                    final long hc = (Long) attrMap.get("MetricHashCode");
                                    metricCache.remove(hc);
                                }
                            } catch (Exception x) {
                                log.error("Expiry Task Failure", x);
                            }
                        }
                    }));
                }
                final long dispatchElapsed = System.currentTimeMillis() - startTime;
                lastExpiryDispatchTime.set(dispatchElapsed);
                int fails = 0;
                for (Future<?> f : taskFutures) {
                    try {
                        f.get();
                    } catch (Exception x) {
                        fails++;
                    }
                }
                final long expiryElapsed = System.currentTimeMillis() - startTime;
                final int exp = expiredMetricCount.get();
                if (exp != 0) {
                    log.info("Expiry Dispatch for [{}] Metrics Completed in [{}] ms. Expired [{}] metrics.",
                            metricObjectNames.length, dispatchElapsed, exp);
                }

                lastExpiryTime.set(expiryElapsed);
                if (log.isDebugEnabled())
                    log.debug("Expiry Completed in [{}] ms. Tasks: {}, Fails: {}", expiryElapsed,
                            taskFutures.size(), fails);
            }
        }
    }, "MetricExpiryThread");
    expiryThread.setDaemon(true);
    expiryThread.setPriority(Thread.MAX_PRIORITY);
    expiryThread.start();
    JMXHelper.registerMBean(this, OBJECT_NAME);
}

From source file:com.stimulus.archiva.search.StandardSearch.java

protected void search(Query query, Filter queryFilter, Sort sort) throws MessageSearchException {
    try {/*from  w ww . jav a2  s .  c  o m*/
        logger.debug("start search  {searchquery='" + getSearchQuery() + "'}");

        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
        results.clear();
        totalHits = getMaxSearchResults();
        TopFieldDocs topDocs = searchers.search(query, queryFilter, totalHits, sort);
        totalHits = topDocs.scoreDocs.length;
        for (int i = 0; i < totalHits; i++) {
            results.add(new LuceneResult(searchers, topDocs.scoreDocs[i]));
        }
        logger.info("search executed successfully {query='" + getSearchQuery() + "',returnedresults='"
                + results.size() + "'}");
    } catch (IOException io) {
        throw new MessageSearchException(
                "failed to execute search query {searchquery='" + getSearchQuery() + "}", io, logger,
                ChainedException.Level.DEBUG);
    }
}

From source file:net.sf.golly.HelpActivity.java

private String DownloadFile(String urlstring, String filepath) {
    // we cannot do network connections on main thread, so we do the
    // download on a new thread, but we have to wait for it to finish
    final Handler handler = new LooperInterrupter();

    cancelled = false;/*from   w ww.  ja  v a  2s.com*/
    progbar.setProgress(0);
    // don't show proglayout immediately
    // proglayout.setVisibility(LinearLayout.VISIBLE);

    dresult = "";
    final String durl = urlstring;
    final String dfile = filepath;
    Thread download_thread = new Thread(new Runnable() {
        public void run() {
            dresult = downloadURL(durl, dfile);
            handler.sendMessage(handler.obtainMessage());
        }
    });

    download_thread.setPriority(Thread.MAX_PRIORITY);
    download_thread.start();

    // wait for thread to finish
    try {
        Looper.loop();
    } catch (RuntimeException re) {
    }

    proglayout.setVisibility(LinearLayout.INVISIBLE);

    if (dresult.length() > 0 && !cancelled) {
        Toast.makeText(this, "Download failed! " + dresult, Toast.LENGTH_SHORT).show();
    }
    return dresult;
}

From source file:org.apache.cocoon.thread.impl.DefaultThreadPool.java

/**
 * DOCUMENT ME!//from w  w w.j  a  v  a2  s .c  om
 *
 * @param priority
 *                The priority to set as string value.
 *
 * @return The priority as int value.
 */
private int convertPriority(final String priority) {
    if ("MIN".equalsIgnoreCase(priority)) {
        return Thread.MIN_PRIORITY;
    } else if ("NORM".equalsIgnoreCase(priority)) {
        return Thread.NORM_PRIORITY;
    } else if ("MAX".equalsIgnoreCase(priority)) {
        return Thread.MAX_PRIORITY;
    } else {
        logger.warn("Unknown thread priority \"" + priority + "\". Set to \"NORM\".");

        return Thread.NORM_PRIORITY;
    }
}

From source file:net.dv8tion.jda.audio.AudioWebSocket.java

private void setupKeepAliveThread(int keepAliveInterval) {
    keepAliveThread = new Thread("AudioWebSocket WS-KeepAlive Guild: " + guild.getId()) {
        @Override//from  ww w  .j  a  v a2s. com
        public void run() {
            while (socket.isOpen() && !this.isInterrupted()) {
                send(new JSONObject().put("op", 3).put("d", System.currentTimeMillis()).toString());
                try {
                    Thread.sleep(keepAliveInterval);
                } catch (InterruptedException e) {
                    //We were asked to close.
                    //                        e.printStackTrace();
                }
            }
        }
    };
    keepAliveThread.setPriority(Thread.MAX_PRIORITY);
    keepAliveThread.setDaemon(true);
    keepAliveThread.start();
}

From source file:org.puder.trs80.EmulatorActivity.java

private void createRenderThread() {
    if (renderThread != null) {
        return;//from   w ww .j a  v a2s . co  m
    }
    renderThread = new RenderThread(isCasting);
    renderThread.setPriority(Thread.MAX_PRIORITY);
    renderThread.setHardwareSpecs(currentHardware);
    renderThread.setSurfaceHolder(surfaceHolder);
}