List of usage examples for java.lang Thread yield
public static native void yield();
From source file:org.apache.hadoop.hbase.rest.TestRowResource.java
private static Response checkAndDeleteXML(String url, String table, String row, String column, String valueToCheck) throws IOException, JAXBException { RowModel rowModel = new RowModel(row); rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel);/* ww w . j a va 2 s . c o m*/ StringWriter writer = new StringWriter(); marshaller.marshal(cellSetModel, writer); Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString())); Thread.yield(); return response; }
From source file:com.taobao.metamorphosis.gregor.slave.OrderedThreadPoolExecutor.java
/** * {@inheritDoc}//from w w w . ja va2s . com */ @Override public List<Runnable> shutdownNow() { this.shutdown(); final List<Runnable> answer = new ArrayList<Runnable>(); IoCatalog ioCatalog; while ((ioCatalog = this.waitingIoCatalogs.poll()) != null) { if (ioCatalog == EXIT_SIGNAL) { this.waitingIoCatalogs.offer(EXIT_SIGNAL); Thread.yield(); // Let others take the signal. continue; } final TasksQueue sessionTasksQueue = (TasksQueue) ioCatalog.connection .getAttribute(this.getCatalog(ioCatalog)); synchronized (sessionTasksQueue.tasksQueue) { for (final Runnable task : sessionTasksQueue.tasksQueue) { answer.add(task); } sessionTasksQueue.tasksQueue.clear(); } } return answer; }
From source file:com.codefollower.lealone.omid.tso.ClientHandler.java
/** * Start a new transaction// w w w . ja v a 2 s . c o m * * @param channel * @throws IOException */ private void startTransaction() { while (true) {// fill the pipe with as much as request you can if (!((channel.getInterestOps() & Channel.OP_WRITE) == 0)) return; // if (outstandingTransactions.intValue() >= MAX_IN_FLIGHT) if (outstandingTransactions >= MAX_IN_FLIGHT) return; if (curMessage == 0) { LOG.info("No more messages, stopping benchmark"); // wait for all outstanding msgs and then close the channel // if (outstandingTransactions.intValue() == 0) { if (outstandingTransactions == 0) { LOG.info("Close channel"); channel.close().addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { answer.offer(true); } }); } return; } curMessage--; // TimestampRequest tr = new TimestampRequest(); outstandingTransactions++; // outstandingTransactions.incrementAndGet(); // Channels.write(channel, tr); try { super.getNewTimestamp(new SyncCreateCallback()); } catch (IOException e) { LOG.error("Couldn't start transaction", e); } Thread.yield(); } }
From source file:org.apache.hadoop.hbase.regionserver.TestSplitLogWorker.java
@Test(timeout = 60000) public void testRescan() throws Exception { LOG.info("testRescan"); SplitLogCounters.resetCounters();/*from www. j a v a 2 s .c om*/ final ServerName SRV = ServerName.valueOf("svr,1,1"); RegionServerServices mockedRS = getRegionServer(SRV); slw = new SplitLogWorker(zkw, TEST_UTIL.getConfiguration(), mockedRS, neverEndingTask); slw.start(); Thread.yield(); // let the worker start Thread.sleep(100); String task = ZKSplitLog.getEncodedNodeName(zkw, "task"); SplitLogTask slt = new SplitLogTask.Unassigned(MANAGER); zkw.getRecoverableZooKeeper().create(task, slt.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 0, 1, WAIT_TIME); // now the worker is busy doing the above task // preempt the task, have it owned by another worker ZKUtil.setData(zkw, task, slt.toByteArray()); waitForCounter(SplitLogCounters.tot_wkr_preempt_task, 0, 1, WAIT_TIME); // create a RESCAN node String rescan = ZKSplitLog.getEncodedNodeName(zkw, "RESCAN"); rescan = zkw.getRecoverableZooKeeper().create(rescan, slt.toByteArray(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); waitForCounter(SplitLogCounters.tot_wkr_task_acquired, 1, 2, WAIT_TIME); // RESCAN node might not have been processed if the worker became busy // with the above task. preempt the task again so that now the RESCAN // node is processed ZKUtil.setData(zkw, task, slt.toByteArray()); waitForCounter(SplitLogCounters.tot_wkr_preempt_task, 1, 2, WAIT_TIME); waitForCounter(SplitLogCounters.tot_wkr_task_acquired_rescan, 0, 1, WAIT_TIME); List<String> nodes = ZKUtil.listChildrenNoWatch(zkw, zkw.splitLogZNode); LOG.debug(nodes); int num = 0; for (String node : nodes) { num++; if (node.startsWith("RESCAN")) { String name = ZKSplitLog.getEncodedNodeName(zkw, node); String fn = ZKSplitLog.getFileName(name); byte[] data = ZKUtil.getData(zkw, ZKUtil.joinZNode(zkw.splitLogZNode, fn)); slt = SplitLogTask.parseFrom(data); assertTrue(slt.toString(), slt.isDone(SRV)); } } assertEquals(2, num); }
From source file:uk.co.real_logic.aeron.tools.ThwackerTool.java
/** * Worker Thread Method:/*w w w .j a va 2 s .com*/ * Randomly selects a slot out of the publication array and creates a publication * if there isn't an active Publication there already */ public void createPubs() { final Random rand = SeedableThreadLocalRandom.current(); while (running) { if (active) { //Get random pub slot final int i = rand.nextInt(numberOfPublications); final ThwackingElement pub = pubs[i]; pub.tryAddPub(); } Thread.yield(); } allDone.countDown(); LOG.fine("CreatePubs all done!"); }
From source file:org.apache.hadoop.hbase.stargate.TestRowResource.java
void doTestMultiCellGetPutXML() throws IOException, JAXBException { String path = "/" + TABLE + "/fakerow"; // deliberate nonexistent row CellSetModel cellSetModel = new CellSetModel(); RowModel rowModel = new RowModel(ROW_1); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1))); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2))); cellSetModel.addRow(rowModel);// w ww.ja v a2 s. c om rowModel = new RowModel(ROW_2); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_3))); rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_4))); cellSetModel.addRow(rowModel); StringWriter writer = new StringWriter(); marshaller.marshal(cellSetModel, writer); Response response = client.put(path, MIMETYPE_XML, Bytes.toBytes(writer.toString())); Thread.yield(); // make sure the fake row was not actually created response = client.get(path, MIMETYPE_XML); assertEquals(response.getCode(), 404); // check that all of the values were created checkValueXML(TABLE, ROW_1, COLUMN_1, VALUE_1); checkValueXML(TABLE, ROW_1, COLUMN_2, VALUE_2); checkValueXML(TABLE, ROW_2, COLUMN_1, VALUE_3); checkValueXML(TABLE, ROW_2, COLUMN_2, VALUE_4); response = deleteRow(TABLE, ROW_1); assertEquals(response.getCode(), 200); response = deleteRow(TABLE, ROW_2); assertEquals(response.getCode(), 200); }
From source file:com.apporiented.hermesftp.client.FtpTestClient.java
private void executeReceive(TextReceiver l) { Thread t = new Thread(l); t.start();/* w w w .ja v a2 s.c om*/ while (t.isAlive()) { Thread.yield(); } }
From source file:org.geowebcache.georss.GeoRSSPollTask.java
protected void stopSeeding(boolean checkLiveCount) { if (this.seedTasks != null) { int liveCount = 0; for (GWCTask task : seedTasks) { if (task.getState() != STATE.DEAD && task.getState() != STATE.DONE) { task.terminateNicely();/*from w w w. j av a 2s .co m*/ liveCount++; } } Thread.yield(); for (GWCTask task : seedTasks) { if (task.getState() != STATE.DEAD && task.getState() != STATE.DONE) { liveCount++; } } if (!checkLiveCount || liveCount == 0) { return; } try { logger.debug("Found " + liveCount + " running seed threads. Waiting 3s for them to terminate."); Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } liveCount = 0; Iterator<GWCTask> iter = seedTasks.iterator(); while (iter.hasNext()) { GWCTask task = iter.next(); if (task.getState() != STATE.DEAD && task.getState() != STATE.DONE) { liveCount++; } else { iter.remove(); } } if (liveCount > 0) { logger.info(liveCount + " seed jobs are still waiting to terminate, proceeding anyway."); } } else { logger.debug("Found no running seed jobs"); } }
From source file:org.apache.hadoop.hbase.rest.TestGetAndPutResource.java
@Test public void testLatestCellGetJSON() throws IOException, JAXBException { final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; CellSetModel cellSetModel = new CellSetModel(); RowModel rowModel = new RowModel(ROW_4); CellModel cellOne = new CellModel(Bytes.toBytes(COLUMN_1), 1L, Bytes.toBytes(VALUE_1)); CellModel cellTwo = new CellModel(Bytes.toBytes(COLUMN_1), 2L, Bytes.toBytes(VALUE_2)); rowModel.addCell(cellOne);// w ww.j a v a 2 s.c om rowModel.addCell(cellTwo); cellSetModel.addRow(rowModel); String jsonString = jsonMapper.writeValueAsString(cellSetModel); Response response = client.put(path, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString)); assertEquals(response.getCode(), 200); Thread.yield(); response = client.get(path, Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); CellSetModel cellSet = jsonMapper.readValue(response.getBody(), CellSetModel.class); assertTrue(cellSet.getRows().size() == 1); assertTrue(cellSet.getRows().get(0).getCells().size() == 1); CellModel cell = cellSet.getRows().get(0).getCells().get(0); assertEquals(VALUE_2, Bytes.toString(cell.getValue())); assertEquals(2L, cell.getTimestamp()); response = deleteRow(TABLE, ROW_4); assertEquals(response.getCode(), 200); }
From source file:org.apache.hadoop.hbase.rest.RowResourceBase.java
protected static Response checkAndDeleteXML(String url, String table, String row, String column, String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException, JAXBException { RowModel rowModel = new RowModel(row); if (cellsToDelete != null) { for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) { rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue()))); }//from ww w . j a va2 s. com } // Add this at the end rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel); StringWriter writer = new StringWriter(); xmlMarshaller.marshal(cellSetModel, writer); Response response = client.put(url, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString())); Thread.yield(); return response; }