List of usage examples for java.lang Thread yield
public static native void yield();
From source file:com.github.lpezet.antiope.metrics.aws.MetricsUploaderThread.java
@Override public void run() { mLogger.info("MetricsUploaderThread running..."); while (!mCancelled) { try {//from w w w . j a v a2 s.com Iterable<PutMetricDataRequest> oRequests = mQIterator.nextUploadUnits(); for (PutMetricDataRequest req : oRequests) { if (mLogger.isDebugEnabled() && req != null) mLogger.debug("Cloudwatch metric data request: " + req.toString()); mCloudwatchClient.putMetricData(req); Thread.yield(); } } catch (InterruptedException e) { if (!mCancelled) { mLogger.debug("Unexpected interruption ignored"); } } catch (Throwable t) { mLogger.warn("Unexpected condition; soldier on", t); Thread.yield(); } } mLogger.info("MetricsUploaderThread done."); }
From source file:com.googlecode.concurrentlinkedhashmap.MemoryLeakTest.java
@Test public void memoryLeak() throws InterruptedException { timeTasks(threads, new Runnable() { @Override/*from w w w.ja va 2 s . c om*/ public void run() { Long id = Thread.currentThread().getId(); map.put(id, id); for (;;) { map.get(id); Thread.yield(); LockSupport.parkNanos(1L); } } }); }
From source file:io.appium.java_client.android.AndroidDriverTest.java
private String currentActivity() { String currentActivity = null; while (currentActivity == null) { currentActivity = driver.currentActivity(); Thread.yield(); }// w w w.ja v a2s . c o m return currentActivity; }
From source file:com.espertech.esper.core.UpdateDispatchFutureSpin.java
public void execute() { if (!earlier.isCompleted) { long spinStartTime = timeSourceService.getTimeMillis(); while (!earlier.isCompleted) { Thread.yield(); long spinDelta = timeSourceService.getTimeMillis() - spinStartTime; if (spinDelta > msecTimeout) { log.info("Spin wait timeout exceeded in listener dispatch"); break; }//from ww w . j a v a 2 s. co m } } view.execute(); isCompleted = true; earlier = null; }
From source file:org.esa.s2tbx.dataio.openjpeg.OpenJpegUtils.java
public static CommandOutput runProcess(ProcessBuilder builder) throws InterruptedException, IOException { builder.environment().putAll(System.getenv()); StringBuilder output = new StringBuilder(); boolean isStopped = false; final Process process = builder.start(); try (BufferedReader outReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { while (!isStopped) { while (outReader.ready()) { String line = outReader.readLine(); if (line != null && !line.isEmpty()) { output.append(line); }//w w w .ja v a 2 s. c o m } if (!process.isAlive()) { isStopped = true; } else { Thread.yield(); } } outReader.close(); } int exitCode = process.exitValue(); //String output = convertStreamToString(process.getInputStream()); String errorOutput = convertStreamToString(process.getErrorStream()); return new CommandOutput(exitCode, output.toString(), errorOutput); }
From source file:com.espertech.esper.core.service.UpdateDispatchFutureSpin.java
public void execute() { if (!earlier.isCompleted) { long spinStartTime = timeSourceService.getTimeMillis(); while (!earlier.isCompleted) { Thread.yield(); long spinDelta = timeSourceService.getTimeMillis() - spinStartTime; if (spinDelta > msecTimeout) { log.info("Spin wait timeout exceeded in listener dispatch for statement '" + view.getStatementResultService().getStatementName() + "'"); break; }//from w ww. java 2 s. c om } } view.execute(); isCompleted = true; earlier = null; }
From source file:org.hydracache.data.partitioning.ConsistentHashNodePartitionTestConcurrency.java
private void startTestThread(final ConsistentHashNodePartition<ServerNode> circle, final CountDownLatch doneLatch) { new Thread() { @Override//from w w w . j a v a2 s . c o m public void run() { try { messWithHashRing(circle); doneLatch.countDown(); } catch (Exception e) { e.printStackTrace(); failed = true; } } private void messWithHashRing(final ConsistentHashNodePartition<ServerNode> circle) { ServerNode node = new ServerNode(RandomUtils.nextInt(100)); circle.remove(node); Thread.yield(); ServerNode n = circle.get(RandomStringUtils.randomNumeric(5)); assertNotNull(n); Thread.yield(); circle.add(node); } }.start(); }
From source file:coyote.dx.web.TestHtmlWorker.java
@Test public void setHtmlGet() throws IOException { Resource resource = new Resource("http://localhost:" + port + "/data/test.html"); Response response = resource.request(); assertNotNull(response);/*from ww w .j av a 2s.c om*/ while (!response.isComplete()) { Thread.yield(); } Document doc = response.getDocument(); assertNotNull(doc); Elements elements = doc.getAllElements(); System.out.println(doc.toString()); System.out.println("Retrieved document contains " + elements.size() + " elements"); assertTrue(elements.size() >= 40); }
From source file:Model.CacheInMemory.java
@SuppressWarnings("unchecked") public void cleanup() { long now = System.currentTimeMillis(); ArrayList<K> deleteKey = null; synchronized (cacheMap) { MapIterator itr = cacheMap.mapIterator(); deleteKey = new ArrayList<K>((cacheMap.size() / 2) + 1); K key = null;//from w w w .j a v a2 s . co m CacheObject c = null; while (itr.hasNext()) { key = (K) itr.next(); c = (CacheObject) itr.getValue(); if (c != null && (now > (timeToLive + c.lastAccessed))) { deleteKey.add(key); } } } for (K key : deleteKey) { synchronized (cacheMap) { cacheMap.remove(key); } Thread.yield(); } }
From source file:org.fcrepo.modeshape.ModeshapeServer.java
private void start(boolean benchEnabled, int num, long size, int threads) throws Exception { RepositoryConfiguration cfg = RepositoryConfiguration .read(this.getClass().getClassLoader().getResourceAsStream("repository.json"), "repo"); ModeShapeEngine engine = new ModeShapeEngine(); engine.start();//from w w w. jav a 2 s . co m Repository repo = engine.deploy(cfg); repo.login(); while (engine.getRepositoryState("repo") != ModeShapeEngine.State.RUNNING) { Thread.yield(); } System.out.println("Modeshape is up and running."); if (benchEnabled) { System.out.println("Enter 'S' to start the tests:"); Scanner scan = new Scanner(System.in); while (!scan.hasNextLine()) { Thread.yield(); } String input = scan.next(); if (input.equalsIgnoreCase("s")) { System.out.println("starting tests"); BenchTool tool = new BenchTool(); tool.runBenchMark(repo, num, size, threads); } else { System.out.println("stopping server"); } } }