List of usage examples for java.lang Thread yield
public static native void yield();
From source file:org.apache.zeppelin.notebook.NotebookTest.java
@Test public void testAbortParagraphStatusOnInterpreterRestart() throws InterruptedException, IOException { Note note = notebook.createNote();/* w w w. j a v a 2 s . c o m*/ note.getNoteReplLoader().setInterpreters(factory.getDefaultInterpreterSettingList()); Paragraph p1 = note.addParagraph(); p1.setText("p1"); Paragraph p2 = note.addParagraph(); p2.setText("p2"); Paragraph p3 = note.addParagraph(); p3.setText("p3"); Paragraph p4 = note.addParagraph(); p4.setText("p4"); /* all jobs are ready to run */ assertEquals(Job.Status.READY, p1.getStatus()); assertEquals(Job.Status.READY, p2.getStatus()); assertEquals(Job.Status.READY, p3.getStatus()); assertEquals(Job.Status.READY, p4.getStatus()); /* run all */ note.runAll(); /* all are pending in the beginning (first one possibly started)*/ assertTrue(p1.getStatus() == Job.Status.PENDING || p1.getStatus() == Job.Status.RUNNING); assertEquals(Job.Status.PENDING, p2.getStatus()); assertEquals(Job.Status.PENDING, p3.getStatus()); assertEquals(Job.Status.PENDING, p4.getStatus()); /* wait till first job is terminated and second starts running */ while (p1.isTerminated() == false || (p2.getStatus() == Job.Status.PENDING)) Thread.yield(); assertEquals(Job.Status.FINISHED, p1.getStatus()); assertEquals(Job.Status.RUNNING, p2.getStatus()); assertEquals(Job.Status.PENDING, p3.getStatus()); assertEquals(Job.Status.PENDING, p4.getStatus()); /* restart interpreter */ factory.restart(note.getNoteReplLoader().getInterpreterSettings().get(0).id()); /* pending and running jobs have been aborted */ assertEquals(Job.Status.FINISHED, p1.getStatus()); assertEquals(Job.Status.ABORT, p2.getStatus()); assertEquals(Job.Status.ABORT, p3.getStatus()); assertEquals(Job.Status.ABORT, p4.getStatus()); }
From source file:org.apache.synapse.transport.mail.MailEchoRawXMLTest.java
public void testRoundTripIMAPUTF8Charset() throws Exception { String msgId = UUIDGenerator.getUUID(); Options options = new Options(); options.setTo(new EndpointReference("mailto:synapse.test.7@gmail.com")); options.setReplyTo(new EndpointReference("mailto:synapse.test.0@gmail.com")); options.setAction(Constants.AXIS2_NAMESPACE_URI + "/echoOMElement"); options.setMessageId(msgId);/*from www . j av a 2 s . c o m*/ ServiceClient sender = new ServiceClient(getClientCfgCtx(), null); sender.setOptions(options); sender.fireAndForget(createKoreanPayload()); Thread.yield(); Thread.sleep(1000 * 10); Object reply = null; boolean replyNotFound = true; int retryCount = 3; while (replyNotFound) { log.debug("Checking for response ... with MessageID : " + msgId); reply = getMessage(msgId); if (reply != null) { replyNotFound = false; } else { if (retryCount-- > 0) { Thread.sleep(10000); } else { break; } } } if (reply != null && reply instanceof String) { log.debug("Result Body : " + reply); XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader((String) reply)); SOAPEnvelope env = new StAXSOAPModelBuilder(reader).getSOAPEnvelope(); if (env != null) { AXIOMXPath xpath = new AXIOMXPath("//my:myValue"); xpath.addNamespace("my", "http://localhost/axis2/services/EchoXMLService"); Object result = xpath.evaluate(env); if (result != null && result instanceof OMElement) { assertEquals(KOREAN_TEXT, ((OMElement) result).getText()); } } } else { fail("Did not receive the reply mail"); } }
From source file:uk.co.real_logic.aeron.tools.ThwackerTool.java
/** * Worker Thread Method:/*from w w w .j ava 2 s . c om*/ * Randomly selects a publication and deletes it if no other threads are using that specific publication */ public void deletePubs() { final Random rand = SeedableThreadLocalRandom.current(); int i; ThwackingElement pub; while (running) { if (active) { //Get random pub slot i = rand.nextInt(numberOfPublications); pub = pubs[i]; pub.tryRemovePub(); } Thread.yield(); } allDone.countDown(); LOG.fine("DeletePubs all done!"); }
From source file:edu.mit.fss.DefaultFederate.java
@Override public void stop() { logger.trace("Stopping the federation..."); if (running.get()) { stopping.set(true);//from w ww. ja va 2s. co m // wait until execution is stopped while (stopping.get()) { Thread.yield(); } } fireExecutionStoppedEvent(); }
From source file:org.apache.hadoop.hbase.rest.TestRowResource.java
private static Response checkAndDeleteValuePB(String url, String table, String row, String column, String valueToCheck) throws IOException { 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 va2s.c o m*/ Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput()); Thread.yield(); return response; }
From source file:org.mule.transport.ldap.functional.MuleEmbeddedTestCase.java
public synchronized void testDispatchReceiveSearchMultipleWithDelete() throws Exception { final MuleClient client = new MuleClient(muleContext); final int addCount = 4; LDAPAddRequest last = null;/*from w ww . j ava 2s . com*/ for (int i = 0; i < addCount; i++) { client.dispatch("ldap://ldap.out", last = TestHelper.getRandomEntryAddRequest(), null); } // time for processing Thread.yield(); Thread.sleep(10000); client.dispatch("ldap://ldap.out", new LDAPDeleteRequest(last.getEntry().getDN(), null), null); // time for processing Thread.yield(); Thread.sleep(10000); // we send a message on the endpoint we created, i.e. vm://Single client.dispatch("ldap://ldap.out/cn.payload", "*", null); // time for processing Thread.yield(); Thread.sleep(10000); MuleMessage result = null; MuleMessage lastResult = null; int count = 0; int tryCount = 0; // addCount * AddResponses, addCount * Search Responses, 1x Search // Result // ok, 1 delete response final int expected = (2 * addCount) + 1 - 1 + 1; // Wait until all dispatched messages are processed by DS while ((tryCount < 20) && (connector.getOutstandingMessageCount() != 6)) { Thread.yield(); Thread.sleep(2000); logger.debug(tryCount + ".try: Outstanding are " + connector.getOutstandingMessageCount()); tryCount++; } assertTrue("Outstanding message count (" + connector.getOutstandingMessageCount() + ") not expected (" + 6 + ")", connector.getOutstandingMessageCount() == 6); // time for processing Thread.yield(); Thread.sleep(10000); logger.debug("Outstanding: " + connector.getOutstandingMessageCount()); while (true) { result = client.request("ldap://ldap.in", 20000); if (result == null) { logger.debug("The " + count + ". message was null"); break; } logger.debug(LDAPUtils.dumpLDAPMessage(result.getPayload())); lastResult = result; count++; } if (count != expected) { logger.warn("count (" + count + ") != expected (" + expected + ")"); } assertNull("result was not null", result); assertNotNull("lastResult was null", lastResult); assertTrue(lastResult.getPayload().getClass().toString() + " instead of LDAPResponse", lastResult.getPayload() instanceof LDAPResponse); // TODO not predictable assertTrue( ((LDAPResponse) lastResult.getPayload()).getType() + " type not expected (" + LDAPMessage.SEARCH_RESULT + ")", ((LDAPResponse) lastResult.getPayload()).getType() == LDAPMessage.SEARCH_RESULT); assertTrue("count (" + count + ") != expected (" + expected + ")", count == expected); try { DSManager.getInstance().stop(); } catch (final Exception e) { } }
From source file:edu.mit.fss.DefaultFederate.java
@Override public void terminate() { logger.trace("Terminating the federate."); if (running.get()) { terminating.set(true);/*ww w . j a va 2s. c om*/ // wait until execution is terminated while (terminating.get()) { Thread.yield(); } } if (initialized.get()) { initialized.set(false); // delete all simulation objects from federation synchronized (localObjects) { for (SimObject object : localObjects) { ambassador.scheduleObjectDeletion(object); } } } ambassador.terminate(); fireExecutionTerminatedEvent(); }
From source file:com.apporiented.hermesftp.client.FtpTestClient.java
private void executeReceive(RawReceiver l) { Thread t = new Thread(l); t.start(); while (t.isAlive()) { Thread.yield(); } }
From source file:org.parosproxy.paros.model.Session.java
protected void open(String fileName) throws DatabaseException, IOException, Exception { // TODO extract into db specific classes?? if (Database.DB_TYPE_HSQLDB.equals(model.getDb().getType())) { configuration = new ZapXmlConfiguration(new File(fileName)); sessionId = configuration.getLong(SESSION_ID); sessionName = configuration.getString(SESSION_NAME, ""); sessionDesc = configuration.getString(SESSION_DESC, ""); } else {/*from w w w. j av a 2s . com*/ this.setSessionId(Long.parseLong(fileName)); } model.getDb().close(false); model.getDb().open(fileName); this.fileName = fileName; //historyList.removeAllElements(); if (!Constant.isLowMemoryOptionSet()) { SiteNode newRoot = new SiteNode(siteTree, -1, Constant.messages.getString("tab.sites")); siteTree.setRoot(newRoot); } // update history reference List<Integer> list = model.getDb().getTableHistory().getHistoryIdsOfHistType(getSessionId(), HistoryReference.TYPE_PROXIED, HistoryReference.TYPE_ZAP_USER); HistoryReference historyRef = null; discardContexts(); // Load the session urls this.setExcludeFromProxyRegexs(sessionUrlListToStingList( model.getDb().getTableSessionUrl().getUrlsForType(RecordSessionUrl.TYPE_EXCLUDE_FROM_PROXY))); this.setExcludeFromScanRegexs(sessionUrlListToStingList( model.getDb().getTableSessionUrl().getUrlsForType(RecordSessionUrl.TYPE_EXCLUDE_FROM_SCAN))); this.setExcludeFromSpiderRegexs(sessionUrlListToStingList( model.getDb().getTableSessionUrl().getUrlsForType(RecordSessionUrl.TYPE_EXCLUDE_FROM_SPIDER))); for (int i = 0; i < list.size(); i++) { // ZAP: Removed unnecessary cast. int historyId = list.get(i).intValue(); try { historyRef = new HistoryReference(historyId); if (View.isInitialised()) { final HistoryReference hRef = historyRef; final HttpMessage msg = historyRef.getHttpMessage(); EventQueue.invokeAndWait(new Runnable() { @Override public void run() { SiteNode sn = getSiteTree().addPath(hRef, msg); if (sn != null) { sn.setIncludedInScope(isIncludedInScope(sn), false); sn.setExcludedFromScope(isExcludedFromScope(sn), false); } } }); } else { SiteNode sn = getSiteTree().addPath(historyRef); if (sn != null) { sn.setIncludedInScope(this.isIncludedInScope(sn), false); sn.setExcludedFromScope(this.isExcludedFromScope(sn), false); } } // ZAP: Load alerts from db historyRef.loadAlerts(); if (i % 100 == 99) Thread.yield(); } catch (Exception e) { // ZAP: Log exceptions log.warn(e.getMessage(), e); } } // update siteTree reference list = model.getDb().getTableHistory().getHistoryIdsOfHistType(getSessionId(), HistoryReference.TYPE_SPIDER, HistoryReference.TYPE_BRUTE_FORCE, HistoryReference.TYPE_SPIDER_AJAX); for (int i = 0; i < list.size(); i++) { // ZAP: Removed unnecessary cast. int historyId = list.get(i).intValue(); try { historyRef = new HistoryReference(historyId); if (View.isInitialised()) { final HistoryReference hRef = historyRef; final HttpMessage msg = historyRef.getHttpMessage(); EventQueue.invokeAndWait(new Runnable() { @Override public void run() { getSiteTree().addPath(hRef, msg); } }); } else { getSiteTree().addPath(historyRef); } if (i % 100 == 99) Thread.yield(); } catch (Exception e) { // ZAP: Log exceptions log.warn(e.getMessage(), e); } } List<RecordContext> contextData = model.getDb().getTableContext().getAllData(); for (RecordContext data : contextData) { Context ctx = this.getContext(data.getContextId()); if (ctx == null) { ctx = new Context(this, data.getContextId()); this.addContext(ctx); if (nextContextIndex <= data.getContextId()) { nextContextIndex = data.getContextId() + 1; } } switch (data.getType()) { case RecordContext.TYPE_NAME: ctx.setName(data.getData()); if (View.isInitialised() && !ctx.getName().equals(String.valueOf(ctx.getIndex()))) { View.getSingleton().renameContext(ctx); } break; case RecordContext.TYPE_DESCRIPTION: ctx.setDescription(data.getData()); break; case RecordContext.TYPE_INCLUDE: ctx.addIncludeInContextRegex(data.getData()); break; case RecordContext.TYPE_EXCLUDE: ctx.addExcludeFromContextRegex(data.getData()); break; case RecordContext.TYPE_IN_SCOPE: ctx.setInScope(Boolean.parseBoolean(data.getData())); break; case RecordContext.TYPE_INCLUDE_TECH: ctx.getTechSet().include(new Tech(data.getData())); break; case RecordContext.TYPE_EXCLUDE_TECH: ctx.getTechSet().exclude(new Tech(data.getData())); break; } } for (Context ctx : contexts) { try { // Set up the URL parameter parser List<String> strs = this.getContextDataStrings(ctx.getIndex(), RecordContext.TYPE_URL_PARSER_CLASSNAME); if (strs.size() == 1) { Class<?> c = ExtensionFactory.getAddOnLoader().loadClass(strs.get(0)); if (c == null) { log.error("Failed to load URL parser for context " + ctx.getIndex() + " : " + strs.get(0)); } else { ParameterParser parser = (ParameterParser) c.getConstructor().newInstance(); strs = this.getContextDataStrings(ctx.getIndex(), RecordContext.TYPE_URL_PARSER_CONFIG); if (strs.size() == 1) { parser.init(strs.get(0)); } parser.setContext(ctx); ctx.setUrlParamParser(parser); } } } catch (Exception e) { log.error("Failed to load URL parser for context " + ctx.getIndex(), e); } try { // Set up the URL parameter parser List<String> strs = this.getContextDataStrings(ctx.getIndex(), RecordContext.TYPE_POST_PARSER_CLASSNAME); if (strs.size() == 1) { Class<?> c = ExtensionFactory.getAddOnLoader().loadClass(strs.get(0)); if (c == null) { log.error("Failed to load POST parser for context " + ctx.getIndex() + " : " + strs.get(0)); } else { ParameterParser parser = (ParameterParser) c.getConstructor().newInstance(); strs = this.getContextDataStrings(ctx.getIndex(), RecordContext.TYPE_POST_PARSER_CONFIG); if (strs.size() == 1) { parser.init(strs.get(0)); } parser.setContext(ctx); ctx.setPostParamParser(parser); } } } catch (Exception e) { log.error("Failed to load POST parser for context " + ctx.getIndex(), e); } try { // Set up the Data Driven Nodes List<String> strs = this.getContextDataStrings(ctx.getIndex(), RecordContext.TYPE_DATA_DRIVEN_NODES); for (String str : strs) { ctx.addDataDrivenNodes(new StructuralNodeModifier(str)); } } catch (Exception e) { log.error("Failed to load data driven nodes for context " + ctx.getIndex(), e); } ctx.restructureSiteTree(); } if (View.isInitialised()) { // ZAP: expand root View.getSingleton().getSiteTreePanel().expandRoot(); } this.refreshScope(); System.gc(); }
From source file:jp.terasoluna.fw.web.thin.LimitedLock.java
/** * ?bN?B/*from w w w . ja v a 2 s .c om*/ * <p> * ?Xbh?bNz_???AX?[p?[NX?\bh?A?bN?B<br> * </p> * <p> * NXg|Cg?B<br> * ?E?bNz_Xbh?\bh?s?AOX??[?B(A)<br> * </p> * @see java.util.concurrent.locks.ReentrantLock#unlock() */ @Override public void unlock() { if (getOwner() != Thread.currentThread()) { return; } synchronized (lock) { super.unlock(); // ?bNXbh?bN(?u)?A // Xbh?AXbhf/?s?ssynchronizedu?bN??A // synchronizedu?bN?B while (getQueueLength() > 0 && getOwner() == null) { Thread.yield(); } } }