List of usage examples for java.lang Thread MIN_PRIORITY
int MIN_PRIORITY
To view the source code for java.lang Thread MIN_PRIORITY.
Click Source Link
From source file:org.fao.geonet.OgpAppHandler.java
private void fillCaches(final ServiceContext context) { final Format formatService = context.getBean(Format.class); // this will initialize the formatter Thread fillCaches = new Thread(new Runnable() { @Override//from w w w . j a va 2s.c o m public void run() { final ServletContext servletContext = context.getServlet().getServletContext(); context.setAsThreadLocal(); ApplicationContextHolder.set(_applicationContext); GeonetWro4jFilter filter = (GeonetWro4jFilter) servletContext .getAttribute(GeonetWro4jFilter.GEONET_WRO4J_FILTER_KEY); @SuppressWarnings("unchecked") List<String> wro4jUrls = _applicationContext.getBean("wro4jUrlsToInitialize", List.class); for (String wro4jUrl : wro4jUrls) { Log.info(Geonet.GEONETWORK, "Initializing the WRO4J group: " + wro4jUrl + " cache"); final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext, "GET", "/static/" + wro4jUrl); final MockHttpServletResponse response = new MockHttpServletResponse(); try { filter.doFilter(servletRequest, response, new MockFilterChain()); } catch (Throwable t) { Log.info(Geonet.GEONETWORK, "Error while initializing the WRO4J group: " + wro4jUrl + " cache", t); } } final Page<Metadata> metadatas = _applicationContext.getBean(MetadataRepository.class) .findAll(new PageRequest(0, 1)); if (metadatas.getNumberOfElements() > 0) { Integer mdId = metadatas.getContent().get(0).getId(); context.getUserSession().loginAs( new User().setName("admin").setProfile(Profile.Administrator).setUsername("admin")); @SuppressWarnings("unchecked") List<String> formattersToInitialize = _applicationContext.getBean("formattersToInitialize", List.class); for (String formatterName : formattersToInitialize) { Log.info(Geonet.GEONETWORK, "Initializing the Formatter with id: " + formatterName); final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext); final MockHttpServletResponse response = new MockHttpServletResponse(); try { formatService.exec("eng", FormatType.html.toString(), mdId.toString(), null, formatterName, Boolean.TRUE.toString(), false, FormatterWidth._100, new ServletWebRequest(servletRequest, response)); } catch (Throwable t) { Log.info(Geonet.GEONETWORK, "Error while initializing the Formatter with id: " + formatterName, t); } } } } }); fillCaches.setDaemon(true); fillCaches.setName("Fill Caches Thread"); fillCaches.setPriority(Thread.MIN_PRIORITY); fillCaches.start(); }
From source file:org.apache.log4j.chainsaw.LogUI.java
/** * Initialises the menu's and toolbars, but does not actually create any of * the main panel components.//www .j ava 2 s . c o m * */ private void initGUI() { setupHelpSystem(); statusBar = new ChainsawStatusBar(this); setupReceiverPanel(); setToolBarAndMenus(new ChainsawToolBarAndMenus(this)); toolbar = getToolBarAndMenus().getToolbar(); setJMenuBar(getToolBarAndMenus().getMenubar()); setTabbedPane(new ChainsawTabbedPane()); getSettingsManager().addSettingsListener(getTabbedPane()); getSettingsManager().configure(getTabbedPane()); /** * This adds Drag & Drop capability to Chainsaw */ FileDnDTarget dnDTarget = new FileDnDTarget(tabbedPane); dnDTarget.addPropertyChangeListener("fileList", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { final List fileList = (List) evt.getNewValue(); Thread thread = new Thread(new Runnable() { public void run() { logger.debug("Loading files: " + fileList); for (Iterator iter = fileList.iterator(); iter.hasNext();) { File file = (File) iter.next(); final Decoder decoder = new XMLDecoder(); try { getStatusBar().setMessage("Loading " + file.getAbsolutePath() + "..."); FileLoadAction.importURL(handler, decoder, file.getName(), file.toURI().toURL()); } catch (Exception e) { String errorMsg = "Failed to import a file"; logger.error(errorMsg, e); getStatusBar().setMessage(errorMsg); } } } }); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } }); applicationPreferenceModelPanel = new ApplicationPreferenceModelPanel(applicationPreferenceModel); applicationPreferenceModelPanel.setOkCancelActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { preferencesFrame.setVisible(false); } }); KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false); Action closeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { preferencesFrame.setVisible(false); } }; preferencesFrame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE"); preferencesFrame.getRootPane().getActionMap().put("ESCAPE", closeAction); OSXIntegration.init(this); }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
private void saveReminders() { Thread thread = new Thread("Save reminders") { @Override/* ww w.java 2s . com*/ public void run() { store(); } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); }
From source file:org.jajuk.util.UpgradeManager.java
/** * Require user to perform a deep scan.//from w w w.jav a 2s.c o m */ private static void deepScanRequest() { int reply = Messages.getChoice(Messages.getString("Warning.7"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (reply == JOptionPane.CANCEL_OPTION || reply == JOptionPane.NO_OPTION) { return; } if (reply == JOptionPane.YES_OPTION) { final Thread t = new Thread("Device Refresh Thread after upgrade") { @Override public void run() { List<Device> devices = DeviceManager.getInstance().getDevices(); for (Device device : devices) { if (device.isReady()) { device.manualRefresh(false, false, true, null); } } } }; t.setPriority(Thread.MIN_PRIORITY); t.start(); } }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
/** * Plays a sound./* www. j a va2 s. co m*/ * * @param fileName * The file name of the sound to play. * @return The sound Object. */ public static Object playSound(final String fileName) { try { if (StringUtils.endsWithIgnoreCase(fileName, ".mid")) { final Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); final InputStream midiFile = new FileInputStream(fileName); sequencer.setSequence(MidiSystem.getSequence(midiFile)); sequencer.start(); new Thread("Reminder MIDI sequencer") { @Override public void run() { setPriority(Thread.MIN_PRIORITY); while (sequencer.isRunning()) { try { Thread.sleep(100); } catch (Exception ee) { // ignore } } try { sequencer.close(); midiFile.close(); } catch (Exception ee) { // ignore } } }.start(); return sequencer; } else { final AudioInputStream ais = AudioSystem.getAudioInputStream(new File(fileName)); final AudioFormat format = ais.getFormat(); final DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); if (AudioSystem.isLineSupported(info)) { final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); line.open(format); line.start(); new Thread("Reminder audio playing") { private boolean stopped; @Override public void run() { byte[] myData = new byte[1024 * format.getFrameSize()]; int numBytesToRead = myData.length; int numBytesRead = 0; int total = 0; int totalToRead = (int) (format.getFrameSize() * ais.getFrameLength()); stopped = false; line.addLineListener(new LineListener() { public void update(LineEvent event) { if (line != null && !line.isRunning()) { stopped = true; line.close(); try { ais.close(); } catch (Exception ee) { // ignore } } } }); try { while (total < totalToRead && !stopped) { numBytesRead = ais.read(myData, 0, numBytesToRead); if (numBytesRead == -1) { break; } total += numBytesRead; line.write(myData, 0, numBytesRead); } } catch (Exception e) { } line.drain(); line.stop(); } }.start(); return line; } else { URL url = new File(fileName).toURI().toURL(); AudioClip clip = Applet.newAudioClip(url); clip.play(); } } } catch (Exception e) { e.printStackTrace(); if ((new File(fileName)).isFile()) { URL url; try { url = new File(fileName).toURI().toURL(); AudioClip clip = Applet.newAudioClip(url); clip.play(); } catch (MalformedURLException e1) { } } else { String msg = mLocalizer.msg("error.1", "Error loading reminder sound file!\n({0})", fileName); JOptionPane.showMessageDialog(UiUtilities.getBestDialogParent(MainFrame.getInstance()), msg, Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:ti.okhttp.TiOkhttpclient.java
public void send(Object userData) throws UnsupportedEncodingException { aborted = false;//ww w .j av a 2s . c o m int totalLength = 0; needMultipart = false; if (userData != null) { if (userData instanceof HashMap) { HashMap<String, Object> data = (HashMap) userData; boolean isPostOrPutOrPatch = method.equals("POST") || method.equals("PUT") || method.equals("PATCH"); boolean isGet = !isPostOrPutOrPatch && method.equals("GET"); // first time through check if we need multipart for POST for (String key : data.keySet()) { Object value = data.get(key); if (value != null) { // if the value is a proxy, we need to get the actual file object if (value instanceof TiFileProxy) { value = ((TiFileProxy) value).getBaseFile(); } if (value instanceof TiBaseFile || value instanceof TiBlob) { needMultipart = true; break; } } } boolean queryStringAltered = false; for (String key : data.keySet()) { Object value = data.get(key); if (isPostOrPutOrPatch && (value != null)) { // if the value is a proxy, we need to get the actual file object if (value instanceof TiFileProxy) { value = ((TiFileProxy) value).getBaseFile(); } if (value instanceof TiBaseFile || value instanceof TiBlob || value instanceof HashMap) { totalLength += addTitaniumFileAsPostData(key, value); } else { String str = TiConvert.toString(value); addPostData(key, str); totalLength += str.length(); } } else if (isGet) { uri = uri.buildUpon().appendQueryParameter(key, TiConvert.toString(value)).build(); queryStringAltered = true; } } if (queryStringAltered) { this.url = uri.toString(); } } else if (userData instanceof TiFileProxy || userData instanceof TiBaseFile || userData instanceof TiBlob) { Object value = userData; if (value instanceof TiFileProxy) { value = ((TiFileProxy) value).getBaseFile(); } if (value instanceof TiBaseFile || value instanceof TiBlob) { setRawData(titaniumFileAsPutData(value)); } else { setRawData(TiConvert.toString(value)); } } else { setRawData(TiConvert.toString(userData)); } } Log.d(TAG, "Instantiating http request with method='" + method + "' and this url:", Log.DEBUG_MODE); Log.d(TAG, this.url, Log.DEBUG_MODE); clientThread = new Thread(new ClientRunnable(totalLength), "TiHttpClient-" + httpClientThreadCounter.incrementAndGet()); clientThread.setPriority(Thread.MIN_PRIORITY); clientThread.start(); Log.d(TAG, "Leaving send()", Log.DEBUG_MODE); }
From source file:org.jajuk.base.Device.java
/** * Refresh : scan the device to find tracks. * This method is only called from GUI. auto-refresh uses refreshCommand() directly. * /*ww w . jav a 2 s. c o m*/ * @param bAsynchronous : * set asynchronous or synchronous mode * @param bAsk whether we ask for fast/deep scan * @param bAfterMove whether this is called after a device move * @param dirsToRefresh : only refresh specified dirs, or all of them if null */ public void refresh(final boolean bAsynchronous, final boolean bAsk, final boolean bAfterMove, final List<Directory> dirsToRefresh) { if (bAsynchronous) { final Thread t = new Thread("Device Refresh Thread for : " + name) { @Override public void run() { manualRefresh(bAsk, bAfterMove, false, dirsToRefresh); } }; t.setPriority(Thread.MIN_PRIORITY); t.start(); } else { manualRefresh(bAsk, bAfterMove, false, dirsToRefresh); } }
From source file:free.yhc.feeder.model.Utils.java
/** * Get BG task thread priority from shared preference. * @param context//from ww w . java 2 s . c o m * @return * Value of Java Thread priority (between Thread.MIN_PRIORITY and Thread.MAX_PRIORITY) */ public static int getPrefBGTaskPriority() { String prio = sPrefs.getString(getResString(R.string.csbgtask_prio), getResString(R.string.cslow)); if (getResString(R.string.cslow).equals(prio)) return Thread.MIN_PRIORITY; else if (getResString(R.string.csmedium).equals(prio)) return (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 2; else if (getResString(R.string.cshigh).equals(prio)) return Thread.NORM_PRIORITY; else { eAssert(false); return Thread.MIN_PRIORITY; } }
From source file:org.jajuk.base.Device.java
/** * Deep / full Refresh with GUI.// w w w .j a v a 2s. co m */ public void manualRefreshDeep() { final Thread t = new Thread("Device Deep Refresh Thread for : " + name) { @Override public void run() { manualRefresh(false, false, true, null); } }; t.setPriority(Thread.MIN_PRIORITY); t.start(); }