List of usage examples for java.lang Thread interrupted
public static boolean interrupted()
From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
/** * Consumes the given list of {@link Future}S and waits until they have all * completed./*from w w w . j av a 2s . c o m*/ * @param futureTasks the futures to consume */ private <U> void waitUntilCompletion(List<Future<U>> futureTasks) { for (Future<U> futureTask : futureTasks) { try { futureTask.get(); } catch (InterruptedException e) { Thread.interrupted(); } catch (ExecutionException e) { throw new RuntimeException(e); } } }
From source file:com.willwinder.universalgcodesender.connection.TCPConnection.java
/** * Thread to accept data from remote host, and pass it to responseHandler *///from ww w. j a v a 2 s. c o m public void run() { String resp; while (!Thread.interrupted() && !client.isClosed()) { try { if (inStream.ready() && (resp = bufIn.readLine()) != null) { responseMessageHandler.handleResponse(resp + "\n", comm); } } catch (SocketException e) { e.printStackTrace(); return; // terminate thread if disconnected //TODO: at some point, reconnecting should be considered } catch (IOException e) { e.printStackTrace(); return; // terminate thread if disconnected //TODO: at some point, reconnecting should be considered } } }
From source file:com.jaspersoft.jasperserver.export.ExporterImpl.java
protected void invokeModules() { List modules = getModuleRegister().getExporterModules(); moduleIndexElements = new HashMap(); for (Iterator it = modules.iterator(); it.hasNext();) { if (Thread.interrupted()) { throw new RuntimeException("Cancelled"); }//from w ww .jav a 2 s . c om ExporterModule module = (ExporterModule) it.next(); ModuleContextImpl moduleContext = new ModuleContextImpl(module.getId()); module.init(moduleContext); if (module.toProcess()) { commandOut.debug("Module " + module.getId() + " processing"); createModuleElement(module); module.process(); } } }
From source file:net.paoding.spdy.client.netty.ResponseFuture.java
public ResponseFuture<Request, Response> await() throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); }//from ww w . j av a 2 s . com synchronized (this) { while (!done) { checkDeadLock(); waiters++; try { this.wait(); } finally { waiters--; } } } return this; }
From source file:org.apache.hadoop.hbase.replication.regionserver.TestGlobalThrottler.java
@Test public void testQuota() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor table = new HTableDescriptor(tableName); HColumnDescriptor fam = new HColumnDescriptor(famName); fam.setScope(HConstants.REPLICATION_SCOPE_SERIAL); table.addFamily(fam);/*from www . j a v a 2s. com*/ utility1.getAdmin().createTable(table); utility2.getAdmin().createTable(table); Thread watcher = new Thread(() -> { Replication replication = (Replication) utility1.getMiniHBaseCluster().getRegionServer(0) .getReplicationSourceService(); AtomicLong bufferUsed = replication.getReplicationManager().getTotalBufferUsed(); testQuotaPass = true; while (!Thread.interrupted()) { long size = bufferUsed.get(); if (size > 0) { testQuotaNonZero = true; } if (size > 600) { // We read logs first then check throttler, so if the buffer quota limiter doesn't // take effect, it will push many logs and exceed the quota. testQuotaPass = false; } Threads.sleep(50); } }); watcher.start(); try (Table t1 = utility1.getConnection().getTable(tableName); Table t2 = utility2.getConnection().getTable(tableName)) { for (int i = 0; i < 50; i++) { Put put = new Put(ROWS[i]); put.addColumn(famName, VALUE, VALUE); t1.put(put); } long start = EnvironmentEdgeManager.currentTime(); while (EnvironmentEdgeManager.currentTime() - start < 180000) { Scan scan = new Scan(); scan.setCaching(50); int count = 0; try (ResultScanner results = t2.getScanner(scan)) { for (Result result : results) { count++; } } if (count < 50) { LOG.info("Waiting all logs pushed to slave. Expected 50 , actual " + count); Threads.sleep(200); continue; } break; } } watcher.interrupt(); Assert.assertTrue(testQuotaPass); Assert.assertTrue(testQuotaNonZero); }
From source file:gobblin.cluster.StreamingJobConfigurationManager.java
private void fetchJobSpecs() throws ExecutionException, InterruptedException { List<Pair<SpecExecutorInstance.Verb, Spec>> changesSpecs = (List<Pair<SpecExecutorInstance.Verb, Spec>>) this.specExecutorInstanceConsumer .changedSpecs().get();//from ww w.ja va 2 s. c o m // propagate thread interruption so that caller will exit from loop if (Thread.interrupted()) { throw new InterruptedException(); } for (Pair<SpecExecutorInstance.Verb, Spec> entry : changesSpecs) { SpecExecutorInstance.Verb verb = entry.getKey(); if (verb.equals(SpecExecutorInstance.Verb.ADD)) { // Handle addition JobSpec jobSpec = (JobSpec) entry.getValue(); postNewJobConfigArrival(jobSpec.getUri().toString(), jobSpec.getConfigAsProperties()); } else if (verb.equals(SpecExecutorInstanceConsumer.Verb.UPDATE)) { // Handle update JobSpec jobSpec = (JobSpec) entry.getValue(); postUpdateJobConfigArrival(jobSpec.getUri().toString(), jobSpec.getConfigAsProperties()); } else if (verb.equals(SpecExecutorInstanceConsumer.Verb.DELETE)) { // Handle delete Spec anonymousSpec = (Spec) entry.getValue(); postDeleteJobConfigArrival(anonymousSpec.getUri().toString(), new Properties()); } } }
From source file:com.mgmtp.perfload.core.client.web.flow.DefaultRequestFlowHandlerTest.java
@AfterMethod public void clearInterruptStatus() { Thread.interrupted(); }
From source file:net.minecraftforge.fml.server.FMLServerHandler.java
@Override public void queryUser(StartupQuery query) throws InterruptedException { if (query.getResult() == null) { FMLLog.warning("%s", query.getText()); query.finish();/* w w w . j ava 2 s . co m*/ } else { String text = query.getText() + "\n\nRun the command /fml confirm or or /fml cancel to proceed." + "\nAlternatively start the server with -Dfml.queryResult=confirm or -Dfml.queryResult=cancel to preselect the answer."; FMLLog.warning("%s", text); if (!query.isSynchronous()) return; // no-op until mc does commands in another thread (if ever) boolean done = false; while (!done && server.isServerRunning()) { if (Thread.interrupted()) throw new InterruptedException(); DedicatedServer dedServer = (DedicatedServer) server; // rudimentary command processing, check for fml confirm/cancel and stop commands synchronized (dedServer.pendingCommandList) { for (Iterator<PendingCommand> it = GenericIterableFactory .newCastingIterable(dedServer.pendingCommandList, PendingCommand.class).iterator(); it .hasNext();) { String cmd = it.next().command.trim().toLowerCase(); if (cmd.equals("/fml confirm")) { FMLLog.info("confirmed"); query.setResult(true); done = true; it.remove(); } else if (cmd.equals("/fml cancel")) { FMLLog.info("cancelled"); query.setResult(false); done = true; it.remove(); } else if (cmd.equals("/stop")) { StartupQuery.abort(); } } } Thread.sleep(10L); } query.finish(); } }
From source file:com.titilink.camel.rest.util.OtherUtil.java
/** * ?sleep?object.wait/*w ww . j ava 2s .com*/ * * @param lockObj ? * @param sometime ?? * @throws InterruptedException -- */ public static void blockSomeTime(final Object lockObj, long sometime) throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); } synchronized (lockObj) { long waitTime = sometime; long start = OtherUtil.getCurrentTime(); try { for (;;) { if (waitTime > 0) { lockObj.wait(waitTime); } else { break; } waitTime = sometime - (OtherUtil.getCurrentTime() - start); } } catch (InterruptedException ex) { lockObj.notifyAll(); throw ex; } } }
From source file:org.apache.nifi.controller.scheduling.ProcessorLifecycleIT.java
private void assertCondition(final Supplier<Boolean> supplier, final long delayToleranceMillis) { final long startTime = System.currentTimeMillis(); while (((System.currentTimeMillis() - startTime) < delayToleranceMillis) && !supplier.get()) { try {/*from w w w. j a va 2 s . c om*/ Thread.sleep(50); } catch (InterruptedException ex) { Thread.interrupted(); break; } } assertTrue(supplier.get()); }