下面列出了java.lang.Thread#sleep ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void run() {
_model.setStatus("Started");
_model.setStopping(false);
_runThread = Thread.currentThread();
_model.setRunning(true);
while (!_model.isStopping()) {
// queue them as fast as they come, sleep a bit otherwise
if (!queueRequests()) {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {}
} else {
Thread.yield();
}
}
_fetcherQueue.clearRequestQueue();
_model.setRunning(false);
_runThread = null;
_model.setStatus("Stopped");
}
public boolean stop() {
_stop = true;
try {
_serversocket.close();
} catch (IOException e) {
e.printStackTrace();
}
if (!_stopped) {
for (int i=0; i<20; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {}
if (_stopped) {
return true;
}
}
return false;
} else {
return true;
}
}
public static void main(String[] args) {
System.gc();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
public static void main(String[] args) {
System.gc();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
private void pollEditsNew(int numRetries) throws IOException {
for (int i = 0; i < numRetries; i++) {
if (editsNewExists())
break;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new IOException("Standby: - received interruption");
}
LOG.info("Standby: - retrying to check if edits.new exists... try: "
+ i);
}
}
private void updateStatus(SparkHistoryServer hs, String state) {
for (int i=0; i<3; i++) {
try {
setCRStatus(state, hs.getNamespace(), hs.getName() );
break;
}
catch(Exception e) {
log.warn("failed to update status {} for {} in {}", state, hs.getName(), hs.getNamespace());
try {Thread.sleep(500);} catch(Exception t) {}
}
}
}
public void waitDelaysFinish() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public void emergencyStop() {
// dangerous - stops all motors!
BluetoothGattCharacteristic characteristics;
characteristics = uuid2characteristics("9a66fa0c-0800-9191-11e4-012d1540cb8e"); // handle 0x46
byte [] arr = { 4, (byte)mEmergencyCounter, 2, 0, 4, 0 };
characteristics.setValue( arr );
mBluetoothLeService.writeCharacteristic(characteristics);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
mEmergencyCounter++;
}
public static void main(String[] args) {
System.gc();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}
private static void sleep(long msec) {
try { Thread.sleep(msec); } catch (InterruptedException e) {}
}
private static void sleep(long msec) {
try { Thread.sleep(msec); } catch (InterruptedException e) {}
}
public static void main(String[] args) throws Exception {
try {
//Move the mouse out, because it could interfere with the test.
Robot r = new Robot();
r.setAutoDelay(50);
r.mouseMove(0, 0);
sleep();
SwingUtilities.invokeAndWait(FullScreenAfterSplash::createAndShowGUI);
sleep();
Point fullScreenButtonPos = frame.getLocation();
if(System.getProperty("os.version").equals("10.9"))
fullScreenButtonPos.translate(frame.getWidth() - 10, frame.getHeight()/2);
else
fullScreenButtonPos.translate(55,frame.getHeight()/2);
r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
//Cant use waitForIdle for full screen transition.
int waitCount = 0;
while (!windowEnteringFullScreen) {
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
waitCount = 0;
while (!windowEnteredFullScreen) {
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
} finally {
if (frame != null) {
frame.dispose();
}
}
}
public void init() {
// note at at least BD characteristics notification is "must have" otherwise it does not start
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fb0f-0800-9191-11e4-012d1540cb8e"), true); // 0xCO
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fb0e-0800-9191-11e4-012d1540cb8e"), true); // 0xBD
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fb1b-0800-9191-11e4-012d1540cb8e"), true); // 0xE4
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fb1c-0800-9191-11e4-012d1540cb8e"), true); // 0xE7
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fd22-0800-9191-11e4-012d1540cb8e"), true); // 0x113
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fd23-0800-9191-11e4-012d1540cb8e"), true); // 0x116
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fd24-0800-9191-11e4-012d1540cb8e"), true); // 0x119
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fd52-0800-9191-11e4-012d1540cb8e"), true); // 0x123
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fd53-0800-9191-11e4-012d1540cb8e"), true); // 0x126
sleep( 50 );
mBluetoothLeService.setCharacteristicNotification(uuid2characteristics("9a66fd54-0800-9191-11e4-012d1540cb8e"), true); // 0x129
sleep(50);
// TODO start all available notifications
// setAllNotification(true);
for( int i=0; i < 20; i++){
BluetoothGattCharacteristic characteristics;
characteristics = uuid2characteristics("9a66fa1e-0800-9191-11e4-012d1540cb8e"); // handle 0x7C
byte[] value = new byte[3];
value[0] = (byte) (0x1);
value[1] = (byte) (i+1);
value[2] = (byte) (i+1);
characteristics.setValue(value);
mBluetoothLeService.writeCharacteristic(characteristics);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
System.out.println("The test is applicable only to Mac OS X. Passed");
return;
}
try {
//Move the mouse out, because it could interfere with the test.
Robot r = new Robot();
r.mouseMove(0, 0);
sleep();
SwingUtilities.invokeAndWait(FullScreenAfterSplash::createAndShowGUI);
sleep();
Point fullScreenButtonPos = frame.getLocation();
fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
//Cant use waitForIdle for full screen transition.
int waitCount = 0;
while (!windowEnteringFullScreen) {
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
waitCount = 0;
while (!windowEnteredFullScreen) {
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
} finally {
if (frame != null) {
frame.dispose();
}
}
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
System.out.println("The test is applicable only to Mac OS X. Passed");
return;
}
try {
//Move the mouse out, because it could interfere with the test.
Robot r = new Robot();
r.mouseMove(0, 0);
sleep();
SwingUtilities.invokeAndWait(FullScreenAfterSplash::createAndShowGUI);
sleep();
Point fullScreenButtonPos = frame.getLocation();
fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
//Cant use waitForIdle for full screen transition.
int waitCount = 0;
while (!windowEnteringFullScreen) {
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
waitCount = 0;
while (!windowEnteredFullScreen) {
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
} finally {
if (frame != null) {
frame.dispose();
}
}
}
@Test
public void testRemoveStaleProvidersOfClusterController() throws Exception {
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
discoveryQos.setDiscoveryTimeoutMs(DISCOVERY_TIMEOUT);
discoveryQos.setRetryIntervalMs(DISCOVERY_TIMEOUT + 1L);
discoveryQos.setCacheMaxAgeMs(0L);
MessagingQos messagingQos = new MessagingQos();
messagingQos.setTtl_ms(MESSAGING_TTL);
final Future<Void> future = new Future<Void>();
// create first joynr cluster controller runtime
runtimeFirst = createRuntime();
// register provider
registerProvider(runtimeFirst);
// shutdown first cluster controller
if (testProvider != null) {
testProvider = null;
}
runtimeFirst.shutdown(false);
// create cluster controller second time
runtimeSecond = createRuntime();
// wait some time to make sure that removeStale has been published and processed
Thread.sleep(1000);
// build proxy when provider are unregistered
runtimeSecond.getProxyBuilder(TEST_DOMAIN, testProxy.class)
.setDiscoveryQos(discoveryQos)
.setMessagingQos(messagingQos)
.build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
fail("runtimeSecond.getProxyBuilder().build() should throw Exception!");
} catch (Exception e) {
boolean isFound = e.getMessage().indexOf("Unable to find provider") != -1 ? true : false;
assertTrue(isFound);
}
runtimeSecond.shutdown(true);
}
private static void sleep() {
try {
Thread.sleep(500);
} catch (InterruptedException ignored) { }
}
private static void sleep(long msec) {
try { Thread.sleep(msec); } catch (InterruptedException e) {}
}
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
System.out.println("The test is applicable only to Mac OS X. Passed");
return;
}
try {
//Move the mouse out, because it could interfere with the test.
Robot r = new Robot();
r.mouseMove(0, 0);
sleep();
SwingUtilities.invokeAndWait(FullScreenAfterSplash::createAndShowGUI);
sleep();
Point fullScreenButtonPos = frame.getLocation();
fullScreenButtonPos.translate(frame.getWidth() - 10, 10);
r.mouseMove(fullScreenButtonPos.x, fullScreenButtonPos.y);
//Cant use waitForIdle for full screen transition.
int waitCount = 0;
while (!windowEnteringFullScreen) {
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
waitCount = 0;
while (!windowEnteredFullScreen) {
Thread.sleep(100);
if (waitCount++ > 10) {
System.err.println("Can't enter full screen mode. Failed.");
System.exit(1);
}
}
} finally {
if (frame != null) {
frame.dispose();
}
}
}
private static void sleep() {
try {
Thread.sleep(500);
} catch (InterruptedException ignored) { }
}