List of usage examples for java.lang Thread setPriority
public final void setPriority(int newPriority)
From source file:com.nesscomputing.syslog4j.server.SyslogServer.java
public static final SyslogServerIF getThreadedInstance(String protocol) throws SyslogRuntimeException { SyslogServerIF server = getInstance(protocol); if (server.getThread() == null) { Thread thread = new Thread(server); thread.setName("SyslogServer: " + protocol); thread.setDaemon(server.getConfig().isUseDaemonThread()); if (server.getConfig().getThreadPriority() > -1) { thread.setPriority(server.getConfig().getThreadPriority()); }//from ww w . j a v a2 s. c o m server.setThread(thread); thread.start(); } return server; }
From source file:net.bither.util.TransactionsUtil.java
public static Thread completeInputsForAddressInBackground(final Address address) { Thread thread = new Thread() { @Override/*w w w . j av a2 s.c o m*/ public void run() { completeInputsForAddress(address); } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); return thread; }
From source file:com.ery.estorm.util.Threads.java
/** * Get a named {@link ThreadFactory} that just builds daemon threads. * // w ww.j a va2 s. c o m * @param prefix * name prefix for all threads created from the factory * @param handler * unhandles exception handler to set for all threads * @return a thread factory that creates named, daemon threads with the supplied exception handler and normal priority */ public static ThreadFactory newDaemonThreadFactory(final String prefix, final UncaughtExceptionHandler handler) { final ThreadFactory namedFactory = getNamedThreadFactory(prefix); return new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = namedFactory.newThread(r); if (handler != null) { t.setUncaughtExceptionHandler(handler); } if (!t.isDaemon()) { t.setDaemon(true); } if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } return t; } }; }
From source file:gate.Main.java
/** Run the user interface. */ protected static void runGui() throws GateException { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // initialise the library and load user CREOLE directories try {//ww w . ja v a 2s .co m Gate.init(); } catch (Throwable t) { log.error("Problem while initialising GATE", t); int selection = JOptionPane.showOptionDialog(null, "Error during initialisation:\n" + t.toString() + "\nDo you still want to start GATE?", "GATE", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] { "Cancel", "Start anyway" }, "Cancel"); if (selection != 1) { System.exit(1); } } //create the main frame, show it SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice().getDefaultConfiguration(); //this needs to run before any GUI component is constructed. applyUserPreferences(); //all the defaults tables have been updated; build the GUI frame = MainFrame.getInstance(gc); if (DEBUG) Out.prln("constructing GUI"); // run the GUI frame.setTitleChangable(true); frame.setTitle(name + " " + version + " build " + build); // Set title from Java properties String title = System.getProperty(GateConstants.TITLE_JAVA_PROPERTY_NAME); if (title != null) { frame.setTitle(title); } // if frame.setTitleChangable(false); // Set icon from Java properties // iconName could be absolute or "gate:/img/..." String iconName = System.getProperty(GateConstants.APP_ICON_JAVA_PROPERTY_NAME); if (iconName != null) { try { frame.setIconImage(Toolkit.getDefaultToolkit().getImage(new URL(iconName))); } catch (MalformedURLException mue) { log.warn("Could not load application icon.", mue); } } // if // Validate frames that have preset sizes frame.validate(); // Center the window Rectangle screenBounds = gc.getBounds(); Dimension screenSize = screenBounds.getSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); //load session if required and available; //do everything from a new thread. Runnable runnable = new Runnable() { @Override public void run() { try { File sessionFile = Gate.getUserSessionFile(); if (sessionFile.exists()) { MainFrame.lockGUI("Loading saved session..."); PersistenceManager.loadObjectFromFile(sessionFile); } } catch (Exception e) { log.warn("Failed to load session data", e); } finally { MainFrame.unlockGUI(); } } }; Thread thread = new Thread(Thread.currentThread().getThreadGroup(), runnable, "Session loader"); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } }); registerCreoleUrls(); }
From source file:org.gtdfree.ApplicationHelper.java
public static synchronized void executeInBackground(Runnable r) { if (backgroundExecutor == null) { backgroundExecutor = new ThreadPoolExecutor(0, 1, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { @Override//from w w w .jav a 2s.c o m public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("BackgroundExecutor"); //$NON-NLS-1$ t.setPriority(Thread.MIN_PRIORITY); t.setDaemon(false); return t; } }); } backgroundExecutor.execute(r); }
From source file:Test.java
public Test() { Runnable runner = new MyRunnable("First"); Thread t = new Thread(runner); t.setPriority(Thread.MIN_PRIORITY); t.start();//from w w w . j a v a 2s . c om runner = new MyRunnable("Second"); t = new Thread(runner); t.setPriority(Thread.MAX_PRIORITY); t.start(); }
From source file:Main.java
public ThreadGroupDemo() { ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); pGroup.setMaxPriority(Thread.MAX_PRIORITY - 2); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); cGroup.setMaxPriority(Thread.NORM_PRIORITY); Thread t1 = new Thread(pGroup, this); t1.setPriority(Thread.MAX_PRIORITY); System.out.println("Starting " + t1.getName()); t1.start();/*from ww w . j av a 2 s . co m*/ Thread t2 = new Thread(cGroup, this); t1.setPriority(Thread.MAX_PRIORITY); System.out.println("Starting " + t2.getName()); t2.start(); System.out.println("Active threads in \"" + pGroup.getName() + "\" = " + pGroup.activeCount()); }
From source file:AnimatedLabel.java
public AnimatedLabel(String gifName, int numGifs) { icons = new Icon[numGifs]; for (int i = 0; i < numGifs; i++) icons[i] = new ImageIcon(gifName + i + ".gif"); setIcon(icons[0]);//www. jav a 2 s. com Thread tr = new Thread(this); tr.setPriority(Thread.MAX_PRIORITY); tr.start(); }
From source file:com.snappydb.snippets.app.fragment.BaseExecutionFragment.java
@Override public void onStart() { super.onStart(); mExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override//from ww w .jav a 2 s. c o m public Thread newThread(@NonNull Runnable runnable) { Thread thread = new Thread(runnable); thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); return thread; } }); try { mSnappyDB = new SnappyDB.Builder(getActivity()).name(getClass().getSimpleName()).build(); } catch (SnappydbException e) { e.printStackTrace(); throw new IllegalStateException("Can't create database"); } }
From source file:com.espertech.esper.core.thread.EngineThreadFactory.java
public Thread newThread(Runnable runnable) { String name = "com.espertech.esper." + prefix + "-" + engineURI + "-" + currThreadCount; currThreadCount++;// ww w .jav a 2 s. c o m Thread t = new Thread(threadGroup, runnable, name); t.setDaemon(true); t.setPriority(threadPriority); if (log.isDebugEnabled()) { log.debug("Creating thread '" + name + "' : " + t + " priority " + threadPriority); } return t; }