List of usage examples for java.lang Thread yield
public static native void yield();
From source file:de.innovationgate.wgpublisher.WGAUsageStatistics.java
public void dispose() { _updateStatsThread.setCanceled(true); while (_updateStatsThread.isAlive()) { Thread.yield(); } }
From source file:org.quickserver.net.server.QuickServer.java
/** * Starts the QuickServer./*from w w w. j a v a 2 s .c o m*/ * * @exception org.quickserver.net.AppException * if Server already running or if it could not load the classes * [ClientCommandHandler, ClientAuthenticationHandler, ClientData]. * @see #startService */ public void startServer() throws AppException { logger.log(Level.FINE, "Starting {0}", getName()); if (isClosed() == false) { logger.log(Level.WARNING, "Server {0} already running.", getName()); throw new AppException("Server " + getName() + " already running."); } blockingMode = getBasicConfig().getServerMode().getBlocking(); if (getSecure().isEnable() && blockingMode == false) { //TODO we need to fix this.. logger.warning( "QuickServer does not support secure servers under non-blocking mode! So will run in blocking mode."); blockingMode = true; getBasicConfig().getServerMode().setBlocking(blockingMode); } if (serverBanner == null) { serverBanner = "\n-------------------------------" + "\n Name : " + getName() + "\n Port : " + getPort() + "\n-------------------------------\n"; logger.finest("Default Server Banner Generated"); } try { loadApplicationClasses(); //load class from Advanced Settings Class clientIdentifierClass = getClass(getBasicConfig().getAdvancedSettings().getClientIdentifier(), true); clientIdentifier = (ClientIdentifier) clientIdentifierClass.newInstance(); clientIdentifier.setQuickServer(QuickServer.this); //load class from ObjectPoolConfig Class poolManagerClass = getClass(getBasicConfig().getObjectPoolConfig().getPoolManager(), true); poolManager = (PoolManager) poolManagerClass.newInstance(); //load class QSObjectPoolMaker Class qsObjectPoolMakerClass = getClass(getBasicConfig().getAdvancedSettings().getQsObjectPoolMaker(), true); qsObjectPoolMaker = (QSObjectPoolMaker) qsObjectPoolMakerClass.newInstance(); loadServerHooksClasses(); processServerHooks(ServerHook.PRE_STARTUP); if (getSecure().isLoad() == true) loadSSLContext(); //v1.4.0 loadBusinessLogic(); } catch (ClassNotFoundException e) { logger.log(Level.SEVERE, "Could not load class/s: " + e, e); throw new AppException("Could not load class/s : " + e); } catch (InstantiationException e) { logger.log(Level.SEVERE, "Could not instantiate class/s: " + e, e); throw new AppException("Could not instantiate class/s: " + e); } catch (IllegalAccessException e) { logger.log(Level.SEVERE, "Illegal access to class/s: " + e, e); throw new AppException("Illegal access to class/s: " + e); } catch (IOException e) { logger.log(Level.SEVERE, "IOException: " + e, e); throw new AppException("IOException: " + e); } catch (Exception e) { logger.log(Level.SEVERE, "Exception: " + e, e); logger.log(Level.FINE, "StackTrace:\n{0}", MyString.getStackTrace(e)); throw new AppException("Exception : " + e); } //v1.3.3 if (getSecurityManagerClass() != null) { System.setSecurityManager(getSecurityManager()); } setServiceState(Service.INIT); t = new Thread(this, "QuickServer - " + getName()); t.start(); do { Thread.yield(); } while (getServiceState() == Service.INIT); if (getServiceState() != Service.RUNNING) { if (exceptionInRun != null) throw new AppException("Could not start server " + getName() + "! Details: " + exceptionInRun); else throw new AppException("Could not start server " + getName()); } lastStartTime = new java.util.Date(); logger.log(Level.FINE, "Started {0}, Date: {1}", new Object[] { getName(), lastStartTime }); }
From source file:org.apache.hadoop.hbase.rest.RowResourceBase.java
protected static Response deleteRow(String table, String row) throws IOException { StringBuilder path = new StringBuilder(); path.append('/'); path.append(table);// w w w. ja va2 s . c o m path.append('/'); path.append(row); Response response = client.delete(path.toString()); Thread.yield(); return response; }
From source file:org.jimcat.services.jobs.Job.java
/** * helper methode to check running state. it may block. * //from w ww. ja v a 2 s . c o m * @return true - job can continue, false if not */ protected JobState checkState() { // check if job is suspended // to test if the job is suspended try aquireing the lock // if suspended the job will automatically wait suspendSemaphore.acquireUninterruptibly(); suspendSemaphore.release(); // check state after suspension synchronized (stateLock) { // be fair Thread.yield(); return state; } }
From source file:org.sonatype.nexus.test.booter.Jetty7NexusBooter.java
/** * Cleans the references to IT-realm, making it garbage collectable (naturally, this can be only "best effort"). *//*from ww w.j a v a 2s . c o m*/ protected void clean() { if (nexusClassloader != null) { try { world.disposeRealm(nexusClassloader.getId()); } catch (NoSuchRealmException e) { // huh? } } // drop references this.jetty7 = null; this.nexusClassloader = null; // give some relief for other (like JVM internal) threads Thread.yield(); // force GC, may help System.gc(); }
From source file:org.apache.hadoop.hbase.rest.TestRowResource.java
@Test public void testSingleCellGetPutBinary() throws IOException { final String path = "/" + TABLE + "/" + ROW_3 + "/" + COLUMN_1; final byte[] body = Bytes.toBytes(VALUE_3); Response response = client.put(path, Constants.MIMETYPE_BINARY, body); assertEquals(response.getCode(), 200); Thread.yield(); response = client.get(path, Constants.MIMETYPE_BINARY); assertEquals(response.getCode(), 200); assertTrue(Bytes.equals(response.getBody(), body)); boolean foundTimestampHeader = false; for (Header header : response.getHeaders()) { if (header.getName().equals("X-Timestamp")) { foundTimestampHeader = true; break; }//www . ja va2 s . c o m } assertTrue(foundTimestampHeader); response = deleteRow(TABLE, ROW_3); assertEquals(response.getCode(), 200); }
From source file:gedi.util.FileUtils.java
/** *Make sure that there is no strong reference left to the buffer! * @param ref//from w w w. j a va2 s . com * @return */ public static boolean unmapSynchronous(WeakReference<MappedByteBuffer> ref) { MappedByteBuffer buffer = ref.get(); if (buffer == null) return true; // first write all data buffer.force(); // need to dispose old direct buffer, see bug // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038 boolean useSystemGc = true; try { ((DirectBuffer) buffer).cleaner().clean(); useSystemGc = false; } catch (Throwable e) { // useSystemGc is already true } finally { } if (useSystemGc) { buffer = null; long start = System.currentTimeMillis(); while (ref.get() != null) { if (System.currentTimeMillis() - start > GC_TIMEOUT_MS) { return false; } System.gc(); Thread.yield(); } } return true; }
From source file:org.mule.transport.ldap.functional.MuleEmbeddedTestCase.java
public void testDispatchReceiveAddStress() throws Exception { final MuleClient client = new MuleClient(muleContext); final int count = 500; final Runnable rec = new Runnable() { public void run() { int current = 0; try { while (current < count) { MuleMessage result = client.request("ldap://ldap.in", 15000); assertNotNull(result); assertTrue(result.getPayload() instanceof LDAPResponse); assertEquals(((LDAPResponse) result.getPayload()).getResultCode(), LDAPException.SUCCESS); assertEquals(((LDAPResponse) result.getPayload()).getType(), LDAPMessage.ADD_RESPONSE); logger.debug("got " + current); current++;//from ww w . ja va2 s.c o m } } catch (Exception e) { fail(e.toString()); } assertTrue(current == count); } }; final Thread t = new Thread(rec); t.start(); Thread.yield(); // we send a message on the endpoint we created, i.e. vm://Single for (int i = 0; i < count; i++) { client.dispatch("ldap://ldap.out", TestHelper.getRandomEntryAddRequest(), null); } t.join(); try { DSManager.getInstance().stop(); } catch (final Exception e) { } }
From source file:org.apache.hadoop.hbase.rest.TestRowResource.java
@Test public void testSingleCellGetJSON() throws IOException, JAXBException { final String path = "/" + TABLE + "/" + ROW_4 + "/" + COLUMN_1; Response response = client.put(path, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_4)); assertEquals(response.getCode(), 200); Thread.yield(); response = client.get(path, Constants.MIMETYPE_JSON); assertEquals(response.getCode(), 200); response = deleteRow(TABLE, ROW_4);/*from w ww . j a va 2 s. c o m*/ assertEquals(response.getCode(), 200); }
From source file:org.apache.hadoop.hbase.rest.RowResourceBase.java
protected static Response putValueJson(String url, String table, String row, String column, String value) throws IOException, JAXBException { RowModel rowModel = new RowModel(row); rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(value))); CellSetModel cellSetModel = new CellSetModel(); cellSetModel.addRow(rowModel);//from w w w. java 2s . c o m String jsonString = jsonMapper.writeValueAsString(cellSetModel); Response response = client.put(url, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString)); Thread.yield(); return response; }