List of usage examples for java.lang Thread interrupted
public static boolean interrupted()
From source file:org.dhus.store.datastore.DefaultDataStoreManager.java
@Override public void addProduct(IngestibleProduct inProduct) throws StoreException { LOGGER.info("Inserting product {} in DataStores", inProduct.getUuid()); List<Throwable> throwables = new ArrayList<>(); for (DataStore datastore : datastores) { if (Thread.interrupted()) { Thread.currentThread().interrupt(); throw new StoreException("Product insertion interrupted"); }/*from ww w.jav a2 s .com*/ try { long duration = System.currentTimeMillis(); datastore.addProduct(inProduct); duration = System.currentTimeMillis() - duration; LOGGER.info("Product {} of UUID {} and size {} stored in {} datastore in {}ms", inProduct.getName(), inProduct.getUuid(), inProduct.getProperty(ProductConstants.DATA_SIZE), datastore.getName(), duration); } catch (ReadOnlyDataStoreException e) { continue; } catch (StoreException | RuntimeException e) { throwables.add(e); } } DataStores.throwErrors(throwables, "addProduct", inProduct.getUuid()); LOGGER.info("Product {} inserted", inProduct.getUuid()); }
From source file:de.tlabs.ssr.g1.client.XmlInputThread.java
@Override public void run() { Log.d(TAG, "(" + this.getId() + ") HELLO"); try {/*from ww w .j a v a 2 s. com*/ // create sax parser SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); // get an xml reader XMLReader xr = sp.getXMLReader(); // set up xml input source XMLChunkInputStream xmlChunkInputStream; synchronized (GlobalData.socketChannel) { xmlChunkInputStream = new XMLChunkInputStream(new ByteArrayBuffer(32 * 1024), GlobalData.socketChannel.socket().getInputStream()); } InputSource inputSource = new InputSource(xmlChunkInputStream); // create handler for scene description and assign it SceneDescrXMLHandler sceneDescrXMLHandler = new SceneDescrXMLHandler(GlobalData.audioScene); xr.setContentHandler(sceneDescrXMLHandler); // parse scene description //Log.d(TAG, "(" + this.getId() + ") parsing description..."); //xmlChunkInputStream.printToLog = true; while (xmlChunkInputStream.bufferNextChunk() && !sceneDescrXMLHandler.receivedSceneDescr()) { // parse and process xml input xr.parse(inputSource); } //xmlChunkInputStream.printToLog = false; // signal that scene description was parsed //Log.d(TAG, "(" + this.getId() + ") sending SCENEPARSED_OK_MSG"); GlobalData.sourcesMoverMsgHandler .sendMessage(GlobalData.sourcesMoverMsgHandler.obtainMessage(SourcesMover.SCENEPARSED_OK_MSG)); // create handler for scene updates and assign it SceneUpdateXMLHandler sceneUpdateXMLHandler = new SceneUpdateXMLHandler(GlobalData.audioScene); xr.setContentHandler(sceneUpdateXMLHandler); // parse scene updates Log.d(TAG, "(" + this.getId() + ") starting xml input loop..."); while (xmlChunkInputStream.bufferNextChunk()) { // parse and process xml input xr.parse(inputSource); // check if we should abort synchronized (abortFlag) { if (abortFlag == true) { break; } } } } catch (Exception e) { Log.d(TAG, "(" + this.getId() + ") Exception " + e.toString() + ": " + e.getMessage()); // check if this thread was aborted and/or stopped by a call to interrupt() if (Thread.interrupted() || abortFlag) { Log.d(TAG, "(" + this.getId() + ") interrupted/aborted"); } else { GlobalData.sourcesMoverMsgHandler.sendMessage(GlobalData.sourcesMoverMsgHandler .obtainMessage(SourcesMover.XMLINPUT_ERR_MSG, e.getMessage())); Log.d(TAG, "(" + this.getId() + ") sending XMLINPUT_ERR_MSG"); } } Log.d(TAG, "(" + this.getId() + ") GOOD BYE"); }
From source file:com.opengamma.bbg.replay.BloombergTickWriter.java
/** * @param ticks// w ww . j a va2s.co m */ private void buildSecurityMapQueue(List<FudgeMsg> ticks) { for (FudgeMsg fudgeMsg : ticks) { String securityDes = fudgeMsg.getString(SECURITY_KEY); if (_securityMapQueue.containsKey(securityDes)) { BlockingQueue<FudgeMsg> queue = _securityMapQueue.get(securityDes); try { queue.put(fudgeMsg); } catch (InterruptedException e) { Thread.interrupted(); s_logger.warn("interrupted from putting message on queue"); } } else { LinkedBlockingQueue<FudgeMsg> queue = new LinkedBlockingQueue<FudgeMsg>(); try { queue.put(fudgeMsg); } catch (InterruptedException e) { Thread.interrupted(); s_logger.warn("interrupted from putting message on queue"); } _securityMapQueue.put(securityDes, queue); } } }
From source file:org.centum.android.play.PlayActivity.java
public void setStack(Stack stack, String session) { this.stack = stack; if (stack != null) { playSession = stack.getPlaySession(session); progressBar = new PlayProgressView(this, stack.getNumberOfCards()); progressBar.setPlayProgressListener(new PlayProgressListener() { @Override/* w w w . j a va2 s . co m*/ public void segmentTapped(int pos) { scrollTo(pos); } }); viewPager.setOnPageChangeListener(this); pagerAdapter = new PlayPagerAdapter(this, stack, playSession); viewPager.setAdapter(pagerAdapter); frameLayout.removeAllViews(); frameLayout.addView(progressBar); playSession.addListener(this); for (Card c : stack.getCards()) { progressBar.setState(stack.getCardPosition(c), playSession.getSessionStat(c)); } } startTime = System.currentTimeMillis(); if (timerThread != null && timerThread.isAlive()) { timerThread.interrupt(); } timerThread = new Thread(new Runnable() { @Override public void run() { while (!Thread.interrupted()) { if (startTime != 0) { handler.post(new Runnable() { @Override public void run() { updatedTimeText(); } }); } try { Thread.sleep(500); } catch (InterruptedException e) { //e.printStackTrace(); //Expected when the activity stops } } } }); timerThread.start(); }
From source file:org.micromanager.plugins.magellan.acq.AcqDurationEstimator.java
private void checkForInterrupt() throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); }//from w w w . java 2s . co m }
From source file:org.hyperic.hq.autoinventory.ScanManager.java
private void mainRunLoop() { while (!shouldExit) { synchronized (scannerList) { if (scannerList.size() > 0) { activeScanner = (Scanner) scannerList.removeFirst(); } else { activeScanner = null;/*w w w . j a v a 2s.c o m*/ } } // Even if no scanner was set, we now run the DefaultScan // periodically. Find out if we should do that now. if (activeScanner == null && isTimeForDefaultScan()) { final StopWatch watch = new StopWatch(); log.info("starting default scan"); rtScanner.scheduleDefaultScan(); log.info("default scan complete " + watch); lastDefaultScan = System.currentTimeMillis(); continue; } if (activeScanner != null) { try { scanInProgress = true; activeScanner.start(); } catch (Exception e) { log.error("Exception starting scanner: " + e, e); } catch (NoClassDefFoundError e) { log.error("Error starting scanner: " + e, e); } finally { synchronized (scannerList) { activeScanner = null; } scanInProgress = false; // clear the plugin shared data, caches, etc. this.apm.endScan(); } } // Check and clear interrupt flag before sleeping if (Thread.interrupted()) continue; try { Thread.sleep(1000); } catch (InterruptedException ie) { } if (isTimeForRtScan()) { try { final StopWatch watch = new StopWatch(); log.info("starting runtime scan"); rtScanner.doRuntimeScan(); log.info("runtime scan complete " + watch); } catch (Exception e) { log.error("Error running runtime autodiscovery scan: " + e, e); } finally { lastRtScan = System.currentTimeMillis(); } } } }
From source file:lockstep.LockstepServer.java
/** * The server cycles collecting a complete set of frame inputs and * forwarding them to all the clients. Differently from the clients, it doesn't * wait any interframe time to process the executionFrameQueues. * If a frame lacks any input from any client, the server stops and waits for * them eventually forcing the clients to stop for synchronization. */// w ww . j a va 2s. com @Override public void run() { try { try { atServerStarted(); handshakePhase(); atHandshakeEnded(); } catch (IOException ioEx) { LOG.fatal("Network exception during handshake"); LOG.fatal(ioEx); return; } while (true) { //check if thread was interrupted, causing termination if (Thread.interrupted()) throw new InterruptedException(); //Wait for any receveingQueue to have some frame to forward executionSemaphore.acquire(); //Collect all the frames available and forward them Map<Integer, FrameInput> frameInputs = collectFrameInputs(); forwardFrameInputs(frameInputs); } } catch (InterruptedException intEx) { closeResources(); } }
From source file:com.microsoft.tfs.client.common.ui.controls.generic.AutocompleteCombo.java
/** * Sets items in the superclass. On GTK adding large numbers of items is * very slow (adding 4700 items can take 5 seconds on a desktop in 2010), so * a batched strategy is used to keep from tying up the UI thread. *///from ww w. j a v a 2s . c o m private void internalSetItems() { if (WindowSystem.isCurrentWindowSystem(WindowSystem.GTK) && items.length >= BATCH_TRIGGER_MIN) { log.debug(MessageFormat.format( "Breaking {0} items in combo into batches of {1} to work-around slow GTK combo", //$NON-NLS-1$ items.length, MAX_BATCH_SIZE)); /* * Start a background thread which posts runnables to the UI thread * to add small-ish batches of items. This lets the UI thread stay * alive between batches. */ synchronized (setItemsThreadLock) { cancelSetItemsThread(); final String[] itemsClone = items.clone(); final Shell shell = getShell(); setItemsThread = new Thread(new Runnable() { @Override public void run() { /* * Divide the list into batches and queue runnables to * add a batch until all done. */ int i = 0; while (i < itemsClone.length) { if (Thread.interrupted() || shell.isDisposed()) { return; } final int batchEndIndexExclusive = Math.min(i + MAX_BATCH_SIZE, itemsClone.length); UIHelpers.runOnUIThread(shell, false, new AddListItemsRunnable(AutocompleteCombo.this, itemsClone, i, batchEndIndexExclusive)); i = batchEndIndexExclusive; } } }); setItemsThread.start(); } } else { cancelSetItemsThread(); super.setItems(items); } }
From source file:it.anyplace.sync.httprelay.server.RelaySessionConnection.java
public void connect() throws IOException { socket = relayConnection.getSocket(); inputStream = socket.getInputStream(); outputStream = socket.getOutputStream(); readerExecutorService.submit(new Runnable() { private final byte[] buffer = new byte[1024 * 10]; //10k @Override/*from www . j a v a2s. c o m*/ public void run() { while (!Thread.interrupted() && !isClosed()) { try { int count = inputStream.read(buffer); if (count < 0) { closeBg(); return; } if (count == 0) { continue; } logger.info("received {} bytes from relay for session {}", count, sessionId); synchronized (inputStream) { try (OutputStream out = new FileOutputStream(getTempFile(), true)) { out.write(buffer, 0, count); } inputStream.notifyAll(); } processorService.submit(new Runnable() { @Override public void run() { eventBus.post(DataReceivedEvent.INSTANCE); } }); } catch (IOException ex) { if (isClosed()) { return; } logger.error("error reading data", ex); closeBg(); return; } } } private void closeBg() { new Thread() { @Override public void run() { close(); } }.start(); } }); }
From source file:org.sourceopen.hadoop.hbase.replication.consumer.FileChannelManager.java
@PreDestroy public void stop() { if (LOG.isInfoEnabled()) { LOG.info("FileChannelManager is pendding to stop."); }//w w w. jav a2 s . c o m stopflag.set(true); fileChannelPool.shutdown(); Thread.interrupted(); }