List of usage examples for java.lang Thread interrupted
public static boolean interrupted()
From source file:frk.gpssimulator.GpsSimulator.java
@Override public void run() { try {/*from ww w . j av a 2s . c o m*/ if (cancel.get()) { destroy(); return; } while (!Thread.interrupted()) { long startTime = new Date().getTime(); if (currentPosition != null) { if (shouldMove) { moveVehicle(); currentPosition.setSpeed(speedInMps); } else { currentPosition.setSpeed(0.0); } if (this.exportPositionsToKml) { kmlService.updatePosition(id, currentPosition); } if (this.useGpsd) { this.gpsdService.updatePosition(currentPosition); } messageChannel.send(MessageBuilder.withPayload(currentPosition).build()); } // wait till next position report is due sleep(startTime); } // loop endlessly } catch (InterruptedException ie) { destroy(); return; } destroy(); }
From source file:org.fseek.simon.swing.util.TreeUtil.java
public static void addChilds(final LinkTreeNode child, final DefaultTreeModel model, boolean showFiles, boolean showHidden, boolean fake) { if (child != null) { File linkDir = child.getLinkDir(); if (linkDir == null) return; if (linkDir.canRead()) { File[] listFiles = linkDir.listFiles((FileFilter) new TreeFileFilter(showHidden, showFiles)); if (listFiles != null) { final int length = listFiles.length; if (fake) { EventQueue.invokeLater(new Runnable() { @Override public void run() { if (length > 0) { fakeNode(child, model); }/*w w w.jav a 2 s . c o m*/ } }); return; } final DefaultMutableTreeNode clear = clear(child); if (clear == null && child.getChildCount() > 0) { return; } deleteAllChilds(child, model, clear); if (Thread.interrupted()) { return; } Arrays.sort(listFiles, DirectoryFileComparator.DIRECTORY_COMPARATOR); Debug.println("Filling node with real data: " + child.getUserObject().toString()); addFiles(listFiles, child, model, showFiles, showHidden); if (clear != null) { EventQueue.invokeLater(new Runnable() { @Override public void run() { model.removeNodeFromParent(clear); } }); } } } } }
From source file:coolmap.application.io.internal.cmatrix.DoubleCMatrixImporter.java
@Override public CMatrix loadData(TFile matrixFolder, JSONObject matrixProperty) throws Exception { String id = matrixProperty.getString(IOTerm.ATTR_ID); String cls = matrixProperty.getString(IOTerm.ATTR_CLASS); String name = matrixProperty.optString(IOTerm.ATTR_NAME); int numColumn = matrixProperty.getInt(IOTerm.ATTR_CMATRIX_NUMCOLUMN); int numRow = matrixProperty.getInt(IOTerm.ATTR_CMATRIX_NUMROW); DoubleCMatrix matrix = new DoubleCMatrix(name, numRow, numColumn, id); //Then standard tsv BufferedReader reader = new BufferedReader(new InputStreamReader( new TFileInputStream(new TFile(matrixFolder + File.separator + IOTerm.FILE_DATA)))); String header = reader.readLine(); String[] ele = header.split("\t", -1); String[] colLabels = new String[ele.length - 1]; for (int i = 1; i < ele.length; i++) { colLabels[i - 1] = ele[i].trim(); }//from ww w. j a va2 s .co m matrix.setColLabels(colLabels); String row; int counter = 0; Double value; while ((row = reader.readLine()) != null) { ele = row.split("\t"); matrix.setRowLabel(counter, ele[0]); for (int i = 1; i < ele.length; i++) { try { value = Double.parseDouble(ele[i]); } catch (Exception e) { value = null; } matrix.setValue(counter, i - 1, value); //Can consider return if (Thread.interrupted()) { throw new InterruptedException("Loading Operation Canceled"); } } counter++; } reader.close();//Close IO return matrix; }
From source file:com.intel.cosbench.driver.operator.Reader.java
private Sample doRead(OutputStream out, String conName, String objName, Config config, Session session) { if (Thread.interrupted()) throw new AbortedException(); InputStream in = null;/*from ww w .j a va 2s .c om*/ CountingOutputStream cout = new CountingOutputStream(out); long start = System.currentTimeMillis(); try { in = session.getApi().getObject(conName, objName, config); if (!hashCheck) IOUtils.copyLarge(in, cout); else if (!validateChecksum(conName, objName, session, in, cout)) return new Sample(new Date(), OP_TYPE, false); } catch (StorageInterruptedException sie) { throw new AbortedException(); } catch (Exception e) { doLogErr(session.getLogger(), "fail to perform read operation", e); return new Sample(new Date(), OP_TYPE, false); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(cout); } long end = System.currentTimeMillis(); Date now = new Date(end); return new Sample(now, OP_TYPE, true, end - start, cout.getByteCount()); }
From source file:games.sudoku.task.BroadCreatorRunnable.java
@Override public void run() { int countGames = boardDao.count(); try {/*ww w . ja v a 2 s . c om*/ run = true; Board board; while (run && countGames < numberOfGames && !Thread.interrupted()) { board = strategy.createGame(); if (board != null) { boardDao.addBoard(board); countGames++; } try { Thread.sleep(sleepTime); } catch (InterruptedException ex) { Logger.getLogger(BoardCreator.class.getName()).log(Level.SEVERE, "Board creator interrupted after creating " + countGames + " boards", ex); break; } } } catch (RuntimeException ex) { Logger.getLogger(BoardCreator.class.getName()).log(Level.SEVERE, "Board creator unexpected exception. Boards created: " + countGames, ex); } finally { Logger.getLogger(BoardCreator.class.getName()).log(Level.INFO, "Board creator finished. Boards created: " + countGames); } }
From source file:com.intel.cosbench.driver.operator.Lister.java
private Sample doList(OutputStream out, String conName, String objName, Config config, Session session) { if (Thread.interrupted()) throw new AbortedException(); InputStream in = null;//from ww w . j a v a 2 s .c om CountingOutputStream cout = new CountingOutputStream(out); doLogWarn(session.getLogger(), "listerrr: " + conName + "/" + objName);//### long start = System.currentTimeMillis(); long xferTime = 0L; try { doLogDebug(session.getLogger(), "worker " + session.getIndex() + " List target " + conName + "/" + objName); in = session.getApi().getList(conName, objName, config); long xferStart = System.currentTimeMillis(); copyLarge(in, cout); xferTime = System.currentTimeMillis() - xferStart; } catch (StorageInterruptedException sie) { doLogErr(session.getLogger(), sie.getMessage(), sie); throw new AbortedException(); } catch (Exception e) { isUnauthorizedException(e, session); errorStatisticsHandle(e, session, conName + "/" + objName); return new Sample(new Date(), getId(), getOpType(), getSampleType(), getName(), false); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(cout); } long end = System.currentTimeMillis(); Date now = new Date(end); return new Sample(now, getId(), getOpType(), getSampleType(), getName(), true, end - start, xferTime, cout.getByteCount()); }
From source file:alluxio.master.FaultTolerantAlluxioMasterProcess.java
@Override public void start() throws Exception { mJournalSystem.start();// w w w. ja v a 2s.c om try { mLeaderSelector.start(getRpcAddress()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } while (!Thread.interrupted()) { if (mServingThread == null) { // We are in secondary mode. Nothing to do until we become the primary. mLeaderSelector.waitForState(State.PRIMARY); LOG.info("Transitioning from secondary to primary"); AbstractJournalSystem.ALLOW_JOURNAL_MODIFY.set(true); mJournalSystem.setMode(Mode.PRIMARY); stopMasters(); LOG.info("Secondary stopped"); startMasters(true); mServingThread = new Thread(() -> { try { startServing(" (gained leadership)", " (lost leadership)"); } catch (Throwable t) { Throwable root = ExceptionUtils.getRootCause(t); if ((root != null && (root instanceof InterruptedException)) || Thread.interrupted()) { return; } LOG.error("Exception thrown in main serving thread. System exiting.", t); System.exit(-1); } }, "MasterServingThread"); mServingThread.start(); LOG.info("Primary started"); } else { // We are in primary mode. Nothing to do until we become the secondary. mLeaderSelector.waitForState(State.SECONDARY); LOG.info("Transitioning from primary to secondary"); AbstractJournalSystem.ALLOW_JOURNAL_MODIFY.set(false); stopServing(); mServingThread.join(mServingThreadTimeoutMs); if (mServingThread.isAlive()) { LOG.error( "Failed to stop serving thread after {}ms. Printing serving thread stack trace " + "and exiting.\n{}", mServingThreadTimeoutMs, ThreadUtils.formatStackTrace(mServingThread)); System.exit(-1); } mServingThread = null; stopMasters(); mJournalSystem.setMode(Mode.SECONDARY); LOG.info("Primary stopped"); startMasters(false); LOG.info("Secondary started"); } } }
From source file:com.subgraph.vega.internal.http.proxy.ConnectionTask.java
private void processingLoop() throws IOException, HttpException { while (!Thread.interrupted() && connection.isOpen()) { HttpContext ctx = new BasicHttpContext(); httpService.handleRequest(connection, ctx); processRequestContext(ctx);//from w w w . ja v a2 s. co m } }
From source file:com.intel.cosbench.driver.operator.Preparer.java
public static void doInit(String conName, Config config, Session session) { if (Thread.interrupted()) throw new AbortedException(); try {//www. j a v a 2s. c o m session.getApi().createContainer(conName, config); } catch (StorageInterruptedException sie) { throw new AbortedException(); } catch (Exception e) { doLogErr(session.getLogger(), "fail to perform prepare operation", e); throw new AgentException(); // mark error } /* no sample is provided for this operation */ }
From source file:org.alfresco.grid.GridHub.java
public void stop() { try {/*from ww w . j av a 2 s . c o m*/ hub.stop(); } catch (Exception e) { logger.error("Problem closing grid hub", e); } Thread.interrupted(); }