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: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 w w . j ava 2s . 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:ro.nextreports.designer.NextReports.java
void start() { long time = System.currentTimeMillis(); final SplashScreen splash = new SplashScreen("splash"); Runnable runnable = new Runnable() { public void run() { for (int i = 0; i <= 100; i += 5) { if (stop) { break; }/*from ww w.j a v a2 s . c om*/ splash.updateSplash(i); try { Thread.sleep(250); } catch (Exception e) { e.printStackTrace(); } } } }; Thread t = new Thread(runnable); t.start(); // redirect output redirectOutput(); // set engine properties System.setProperty(EngineProperties.RUN_PRIORITY_PROPERTY, String.valueOf(Thread.MIN_PRIORITY)); System.setProperty(EngineProperties.RECORDS_YIELD_PROPERTY, String.valueOf(5000)); System.setProperty(EngineProperties.MILLIS_YIELD_PROPERTY, String.valueOf(100)); // set pdf font and encoding Globals.setPdfEncoding(); Globals.setPdfFont(); // set pdf direction and arabic Globals.setPdfDirection(); Globals.setPdfArabicOptions(); // set oracle client path Globals.setOracleClientPath(); // set locale Globals.setLocale(); FontUtil.registerFonts(Globals.getFontDirectories()); // print parameters printParameters(); // create the main frame final MainFrame mainFrame = createMainFrame(); // add global actions GlobalHotkeyManager hotkeyManager = GlobalHotkeyManager.getInstance(); InputMap inputMap = hotkeyManager.getInputMap(); ActionMap actionMap = hotkeyManager.getActionMap(); Action queryPerspectiveAction = new OpenQueryPerspectiveAction(); inputMap.put((KeyStroke) queryPerspectiveAction.getValue(Action.ACCELERATOR_KEY), "queryPerspective"); actionMap.put("queryPerspective", queryPerspectiveAction); Action reportPerspectiveAction = new OpenReportPerspectiveAction(); inputMap.put((KeyStroke) reportPerspectiveAction.getValue(Action.ACCELERATOR_KEY), "reportPerspective"); actionMap.put("reportPerspective", reportPerspectiveAction); disposeSplash(splash); mainFrame.setVisible(true); time = System.currentTimeMillis() - time; LOG.info("Start in " + time + " ms"); // do not show start dialog if we start from server if (Globals.getServerUrl() == null) { showStartDialog(true); showSurveyDialog(); } else { new NextReportsServerRequest(); } }
From source file:com.spoiledmilk.ibikecph.navigation.routing_engine.SMRoute.java
@Override public void onResponseReceived(int requestType, Object response) { switch (requestType) { case SMHttpRequest.REQUEST_GET_ROUTE: JsonNode jsonRoot = ((RouteInfo) response).jsonRoot; if (jsonRoot == null || jsonRoot.path("status").asInt(-1) != 0) { if (listener != null) listener.routeNotFound(); } else {//from www. j a v a 2 s . c o m setupRoute(jsonRoot); if (listener != null) listener.startRoute(); } break; case SMHttpRequest.REQUEST_GET_RECALCULATED_ROUTE: final JsonNode jRoot = ((RouteInfo) response).jsonRoot; if (jRoot == null || jRoot.path("status").asInt() != 0) { if (listener != null) { listener.serverError(); } recalculationInProgress = false; return; } final Handler h = new Handler(); Thread t = new Thread(new Runnable() { @Override public void run() { boolean ok = parseFromJson(jRoot, null, isRouteBroken); // logWaypoints(); if (ok) { approachingTurn = false; h.post(new Runnable() { @Override public void run() { if (lastLocation != null) { visitLocation(lastLocation); } if (visitedLocations != null && visitedLocations.size() > 0) { // visitLocation(visitedLocations.get(visitedLocations.size() - 1)); } if (SMLocationManager.getInstance().hasValidLocation()) { updateDistances(SMLocationManager.getInstance().getLastValidLocation()); } if (listener != null) { listener.routeRecalculationDone(); listener.updateRoute(); } recalculationInProgress = false; } }); } else { h.post(new Runnable() { @Override public void run() { if (listener != null) listener.serverError(); recalculationInProgress = false; } }); } } }); t.setPriority(Thread.MIN_PRIORITY); t.start(); } }
From source file:net.sf.ginp.browser.FolderManagerImpl.java
/** * Gets the picturesInDirectory attribute of the PicCollection object. * *@param relPath Description of the Parameter *@return The picturesInDirectory value *//* w w w.ja v a 2s . c o m*/ private String[] getPicturesInDirectory(final String root, final String relPath) { long duration = System.currentTimeMillis() - picCacheTimeout; if ((picCacheTimeout < 0) || (duration > MAX_CACHE)) { synchronized (picCache) { //Clearing a cache while doing a get can //cause hashmap to hang. Hence all the synchronized blocks picCacheTimeout = System.currentTimeMillis(); picCache.clear(); } } synchronized (picCache) { if (picCache.get(root + relPath) != null) { String[] cached = (String[]) picCache.get(root + relPath); return cached; } } Vector pics = new Vector(); try { File dir = new File(root + relPath); if (dir.isDirectory()) { String[] files = dir.list(); for (int i = 0; i < files.length; i++) { File file = new File(root + relPath + "/" + files[i]); if ((!file.isDirectory()) && ((files[i].toLowerCase()).endsWith(".jpg") || (files[i].toLowerCase()).endsWith(".jpeg"))) { pics.add(files[i]); if (log.isDebugEnabled()) { log.debug("Adding picture file: " + files[i]); } } } // Add Featured Pics File fl = new File(root + relPath + "ginpfolder.xml"); if (fl.exists()) { FileReader fr = new FileReader(fl); LineNumberReader lr = new LineNumberReader(fr); StringBuffer sb = new StringBuffer(); String temp; while ((temp = lr.readLine()) != null) { sb.append(temp + "\n"); } String featuredpicsXML = StringTool.getXMLTagContent("featuredpics", sb.toString()); String[] picsXML = StringTool.splitToArray(featuredpicsXML, "<pic>"); for (int i = 0; i < picsXML.length; i++) { if (picsXML[i].indexOf("</pic>") != -1) { temp = picsXML[i].substring(0, picsXML[i].indexOf("</pic>")); fl = new File(root + relPath + temp); if (fl.exists()) { pics.add(temp); } } } } } } catch (IOException ex) { log.error(ex); } String[] retPictures = new String[pics.size()]; for (int i = 0; i < pics.size(); i++) { retPictures[i] = (String) pics.get(i); } String[] sorted = sortPictures(retPictures); synchronized (picCache) { if (picCache.get(root + relPath) == null) { picCache.put(root + relPath, sorted); } else { return (String[]) picCache.get(root + relPath); } } // Only One Thread Per Directory Should Ever Get Here // (Unless it takes longer than 2 minutes to make) synchronized (MakeThumbs.class) { if ((mth == null) || ((mthThread != null) && !mthThread.isAlive())) { mth = new MakeThumbs(); mthThread = new Thread(mth); mthThread.setDaemon(true); mthThread.setPriority(Thread.MIN_PRIORITY); mthThread.start(); } } mth.addToQueue(root + relPath, sorted); return sorted; }
From source file:org.alfresco.mobile.android.application.managers.RenditionManagerImpl.java
public void display(RenditionRequest request) { // Prerequisites if (session == null) { setSession(SessionUtils.getSession(appContext)); }/* w ww .ja v a 2 s .c o m*/ if (picasso == null) { picasso = new Builder(appContext).build(); } // Cancel any previous request if (picasso != null) { picasso.cancelRequest(request.iv.get()); } // Wrong identifier so display placeholder directly String url = null; if (TextUtils.isEmpty(request.itemId) || session == null) { request.iv.get().setImageResource(request.placeHolderId); return; } // Let's find how to display the itemId switch (request.typeId) { case TYPE_NODE: if (session instanceof RepositorySession) { url = getDocumentRendition(request.itemId, DocumentFolderService.RENDITION_THUMBNAIL); if (request.renditionTypeId == RenditionRequest.RENDITION_PREVIEW) { url = getDocumentRendition(request.itemId, DocumentFolderService.RENDITION_PREVIEW); } startPicasso(url, request); return; } else if (hasReference(request.itemId, request.renditionTypeId)) { url = getReference(request.itemId, request.renditionTypeId); startPicasso(url, request); return; } break; case TYPE_WORKFLOW: url = ((AbstractWorkflowService) session.getServiceRegistry().getWorkflowService()) .getProcessDiagramUrl(request.itemId).toString(); startPicasso(url, request); return; case TYPE_PERSON: if (session instanceof RepositorySession && session.getRepositoryInfo().getMajorVersion() >= OnPremiseConstant.ALFRESCO_VERSION_4) { url = OnPremiseUrlRegistry.getAvatarUrl(session, request.itemId); startPicasso(url, request); return; } else if (hasReference(request.itemId, request.renditionTypeId)) { url = getReference(request.itemId, request.renditionTypeId); startPicasso(url, request); return; } break; default: break; } // We don't know the url associated to the itemId, we need to find it // first. displayPlaceHolder(request.iv, request.placeHolderId); if (getReference(request.itemId, request.renditionTypeId) == null && activityRef != null) { addReference(request.itemId, AWAIT, request.renditionTypeId); urlRetrieverThread thread = new urlRetrieverThread(activityRef.get(), session, request); thread.setPriority(Thread.MIN_PRIORITY); if (request.renditionTypeId == RenditionRequest.RENDITION_PREVIEW) { thread.setPriority(Thread.NORM_PRIORITY); } final AsyncDrawable asyncDrawable = new AsyncDrawable(activityRef.get().getResources(), thread); request.iv.get().setImageDrawable(asyncDrawable); if (thread.getState() == Thread.State.NEW) { thread.start(); } } else { request.iv.get().setImageResource(request.placeHolderId); } }
From source file:net.gleamynode.oil.impl.wal.store.FileLogStore.java
private void parseProperties() { String file;/*from w w w .java2s.c om*/ int maxItemSize; int bufferFlushInterval; int bufferSize; String threadName; int threadPriority; // file file = properties.getProperty(FileLogStoreConstants.PROP_FILE); if (file == null) { throw new IllegalPropertyException(); } // maxItemSize String value = properties.getProperty(FileLogStoreConstants.PROP_MAX_ITEM_SIZE, String.valueOf(FileLogStoreConstants.DEFAULT_MAX_ITEM_SIZE)); try { maxItemSize = Integer.parseInt(value); } catch (Exception e) { throw new IllegalPropertyException(e); } if (maxItemSize <= 0) { throw new IllegalPropertyException(); } // bufferFlushInterval value = properties.getProperty(FileLogStoreConstants.PROP_BUFFER_FLUSH_INTERVAL, String.valueOf(FileLogStoreConstants.DEFAULT_BUFFER_FLUSH_INTERVAL)); try { bufferFlushInterval = Integer.parseInt(value); } catch (Exception e) { throw new IllegalPropertyException(e); } if (bufferFlushInterval < 1) { throw new IllegalPropertyException(); } // bufferSize value = properties.getProperty(FileLogStoreConstants.PROP_BUFFER_SIZE, String.valueOf(FileLogStoreConstants.DEFAULT_BUFFER_SIZE)); try { bufferSize = Integer.parseInt(value); } catch (Exception e) { throw new IllegalPropertyException(e); } if (bufferSize < 1) { throw new IllegalPropertyException(); } // threadName threadName = properties .getProperty(FileLogStoreConstants.PROP_THREAD_NAME, FileLogStoreConstants.DEFAULT_THREAD_NAME) .trim(); if (threadName.length() == 0) { throw new IllegalPropertyException(); } // threadPriority value = properties.getProperty(FileLogStoreConstants.PROP_THREAD_PRIORITY, String.valueOf(FileLogStoreConstants.DEFAULT_THREAD_PRIORITY)); try { threadPriority = Integer.parseInt(value); } catch (Exception e) { throw new IllegalPropertyException(e); } if ((threadPriority < Thread.MIN_PRIORITY) || (threadPriority > Thread.MAX_PRIORITY)) { throw new IllegalPropertyException(); } this.file = new File(file); this.maxItemSize = maxItemSize; this.bufferFlushInterval = bufferFlushInterval; this.bufferSize = bufferSize; this.threadName = threadName; this.threadPriority = threadPriority; }
From source file:ca.farrelltonsolar.classic.ModbusTask.java
private void init(Context ctx) { context = ctx;/*from ww w .j a v a 2 s. c o m*/ readings = new Readings(); dayLogEntry = new LogEntry(); minuteLogEntry = new LogEntry(); Thread.currentThread().setPriority(Thread.MIN_PRIORITY); Log.d(getClass().getName(), String.format("ModbusTask created thread is %s", Thread.currentThread().getName())); }
From source file:io.cloudslang.content.database.services.dbconnection.DBConnectionManager.java
/** * @param aDbType one of the supported db type, for example ORACLE, NETCOOL * @param aDbUrl connection url/*from w w w .j a v a 2 s. c om*/ * @param aUsername username to connect to db * @param aPassword password to connect to db * @return a Connection to db * @throws SQLException */ public synchronized Connection getConnection(DBType aDbType, String aAuthType, String aDbUrl, String aUsername, String aPassword, Properties properties) throws SQLException { if (isEmpty(aDbUrl)) { throw new SQLException("Failed to check out connection dbUrl is empty"); } if (aDbType == null || !(MSSQL_DB_TYPE.equalsIgnoreCase(aDbType.toString()) && AUTH_WINDOWS.equalsIgnoreCase(aAuthType))) { if (isEmpty(aUsername)) { throw new SQLException("Failed to check out connection,username is empty. dburl = " + aDbUrl); } if (isEmpty(aPassword)) { throw new SQLException("Failed to check out connection, password is empty. username = " + aUsername + " dbUrl = " + aDbUrl); } } customizeDBConnectionManager(properties); if (!this.isPoolingEnabled) { //just call driver manager to create connection return this.getPlainConnection(aDbUrl, aUsername, aPassword); } else { //want connection pooling if (aDbType == null) { throw new SQLException("Failed to check out connection db type is null"); } //if the runnable has been shutdown when dbmspoolsize is 0 //then need to resumbit to the thread and start it again if (datasourceCleaner.getState() == STATE_CLEANER.SHUTDOWN) { //submit it to the thread to run cleanerThread = new Thread(datasourceCleaner); cleanerThread.setPriority(Thread.MIN_PRIORITY); cleanerThread.start(); } //will use pooled datasource provider return getPooledConnection(aDbType, aDbUrl, aUsername, aPassword); } }
From source file:com.iwedia.adapters.FragmentTabAdapter.java
/** * Starts background thread./*from w w w .j a v a 2s . c o m*/ */ private synchronized void startThread() { stopThread(); mTimerThread = new Thread(new Runnable() { @Override public void run() { Thread thisThread = Thread.currentThread(); while (true) { if (thisThread == mTimerThread) { mHandler.sendEmptyMessage(MESSAGE_REFRESH_TIME); } try { Thread.sleep(1000); } catch (InterruptedException e) { } } } }); mTimerThread.setPriority(Thread.MIN_PRIORITY); mTimerThread.start(); }
From source file:com.rokolabs.app.common.image.ImageCache.java
public void saveBitmapToDisk(final String data, final File bitmap) { mSavingThreadPool.submit(new Runnable() { @Override/* w w w . j a v a 2 s . c o m*/ public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); saveBitmapToDiskSync(data, bitmap); bitmap.delete(); } }); }