本文整理匯總了Java中java.lang.Thread.sleep方法的典型用法代碼示例。如果您正苦於以下問題:Java Thread.sleep方法的具體用法?Java Thread.sleep怎麽用?Java Thread.sleep使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.Thread
的用法示例。
在下文中一共展示了Thread.sleep方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: finish
import java.lang.Thread; //導入方法依賴的package包/類
private void finish(IORobot bot1, IORobot bot2) throws InterruptedException
{
bot1.finish();
Thread.sleep(200);
bot2.finish();
Thread.sleep(200);
Thread.sleep(200);
// write everything
// String outputFile = this.writeOutputFile(this.gameId, this.engine.winningPlayer());
this.saveGame(bot1, bot2);
System.exit(0);
}
示例2: callingOnStartCommandMultipleTimes
import java.lang.Thread; //導入方法依賴的package包/類
/**
* Test that starting the service is idempotent (only the first one counts).
*/
@Test
public void callingOnStartCommandMultipleTimes() throws Exception {
// Sleep briefly to avoid racing with the first background task.
Thread.sleep(AVOID_BACKGROUND_TASK_RACE_SLEEP_TIME);
Date startTime = service.getServiceStartTime();
int backgroundRunCount = service.getBackgroundTasksRunCount();
Intent intent = new Intent(Robolectric.application, RangzenService.class);
service.onStartCommand(intent, 0, startId);
startId++;
assertEquals("Start time changed calling onStartCommand again",
startTime, service.getServiceStartTime());
assertEquals("Background run count changed calling onStartCommand again",
backgroundRunCount, service.getBackgroundTasksRunCount());
}
示例3: run
import java.lang.Thread; //導入方法依賴的package包/類
@Override
public void run() {
Log.i("netclip", "ClipboardCleanRunnable.run");
int k = 0;
while (k <= 15 * 10 && this.replaced == false) {
Log.i("netclip", "ClipboardCleanRunnable.run - iteration");
try {
Thread.sleep(100);
k++;
} catch (InterruptedException ex) { }
}
if (this.replaced == false) {
Log.i("netclip", "ClipboardCleanRunnable.run - cleaning clipboard");
Clipboard.getInstance(null).reset();
}
Log.i("netclip", "ClipboardCleanRunnable.run - finished execution");
}
示例4: interruptAllIngestorThreads
import java.lang.Thread; //導入方法依賴的package包/類
public void interruptAllIngestorThreads()
{
try
{
for(Thread ingestorThread: this.getIngestorThreads().values())
{
if(ingestorThread.isAlive())
{
ingestorThread.interrupt();
}
}
if(this.reharvesterThread!=null && this.reharvesterThread.isAlive())
this.reharvesterThread.interrupt();
// Give the threads five seconds to try to clean themselves up
Thread.sleep(5000);
}
catch (Exception e1) {}
}
示例5: main
import java.lang.Thread; //導入方法依賴的package包/類
public static void main(String args[]){
Game g = new Game(20,40,1);
Input in = new Input();
in.start();
while(g.play){
try{
g.refresh();
if(in.getState() != Thread.State.WAITING){
g.b.y--;
}else{g.b.y++;}
g.count++;
Thread.sleep(1000/g.fps); //inverse of refresh rate
if(g.count > 5){
throw new Exception();
}
}catch(Exception e){
System.out.println("Game over");
g.play = false;
}
}
}
示例6: finish
import java.lang.Thread; //導入方法依賴的package包/類
@Override
// close the bot processes, save, exit program
public void finish() throws Exception
{
for(Player player : players) {
player.getBot().finish();
}
Thread.sleep(100);
// write everything
try {
this.saveGame();
} catch(Exception e) {
e.printStackTrace();
}
System.out.println("Done.");
System.exit(0);
}
示例7: main
import java.lang.Thread; //導入方法依賴的package包/類
/*************** Testing *******/
public static void main(String []argv) throws InterruptedException {
RTimer rt = new RTimer(), subt, st;
Thread.sleep(100);
subt = rt.sub("sub1");
Thread.sleep(50);
st = subt.sub("sub1.1");
st.resume();
Thread.sleep(10);
st.pause();
Thread.sleep(50);
st.resume();
Thread.sleep(10);
st.pause();
subt.stop();
rt.stop();
System.out.println( rt.toString());
}
示例8: connectToOneServerWithRetry
import java.lang.Thread; //導入方法依賴的package包/類
/**
* Connect to a single server with retry. Limited exponential backoff. No
* timeout. This will run until the process is killed if it's not able to
* connect.
*
* @param server
* hostname:port or just hostname (hostname can be ip).
*/
void connectToOneServerWithRetry(String server) {
int sleep = 1000;
while (runBenchmark) {
try {
client.createConnection(server);
break;
} catch (Exception e) {
log.error(_F("Connection failed - retrying in %d second(s).\n",
sleep / 1000));
try { Thread.sleep(sleep); }
catch (Exception interruted) { }
if (sleep < 8000)
sleep += sleep;
}
}
log.info(_F("Connected to VoltDB node at: %s.\n", server));
}
示例9: finish
import java.lang.Thread; //導入方法依賴的package包/類
/**
* close the bot processes, save, exit program
*/
@Override
public void finish() throws Exception
{
this.player1.getBot().finish();
this.player2.getBot().finish();
Thread.sleep(100);
// write everything
try {
this.saveGame();
} catch(Exception e) {
e.printStackTrace();
}
System.out.println("Done.");
System.exit(0);
}
示例10: tesTokenHandling
import java.lang.Thread; //導入方法依賴的package包/類
@Test
public void tesTokenHandling() {
try {
connection = Mockito.mock(WebSocket.class);
String result;
AuthenticationToken auth = new AuthenticationToken("[email protected]", "123");
JSONReader<AuthenticationToken> tokenReader = new JSONReader<AuthenticationToken>();
String t = tokenReader.JSONWriter(auth);
TokenHandler tok = new TokenHandler(auth, t, connection);
Thread x = new Thread(tok);
x.start();
assertTrue(x.isAlive());
Thread.sleep(1000);
assertFalse(x.isAlive());
}
catch (Exception e) {
}
}
示例11: main
import java.lang.Thread; //導入方法依賴的package包/類
public static void main(String[] args)
{
StringBuilder s = new StringBuilder("Hahaha");
// Notice: void run method are the same to both, but I overloaded it.
Thread t = new Thread(new threadAndRunnable(s)); // this calls void run method
t.start(); // by the Interface Runnable
(new threadAndRunnable()).start(); // this calls a Thread by class Thread()
for(int i=0; i < 10; i++) // And it, only repetely shows a message
{
System.out.println("tchau!");
try{Thread.sleep(90);}catch(InterruptedException e){}
}
}
示例12: run
import java.lang.Thread; //導入方法依賴的package包/類
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");
}
示例13: stop
import java.lang.Thread; //導入方法依賴的package包/類
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;
}
}
示例14: main
import java.lang.Thread; //導入方法依賴的package包/類
public static void main(String[] args) {
final int n = Integer.parseInt(args[0]);
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI(n);
} });
try{
Thread.sleep(4000);
}catch (InterruptedException e){
}
System.exit(0);
}
示例15: assembleDataRasters
import java.lang.Thread; //導入方法依賴的package包/類
protected void assembleDataRasters() throws Exception
{
// Exit if the caller has instructed us to stop production.
if (this.isStopped())
return;
for (SourceInfo info : this.getDataSourceList())
{
// Exit if the caller has instructed us to stop production.
if (this.isStopped())
break;
Thread.sleep(0);
// Don't validate the data source here. Data sources are validated when they're passed to the producer in
// offerDataSource() or offerAllDataSources().
this.assembleDataSource(info.source, info);
}
}