當前位置: 首頁>>代碼示例>>Java>>正文


Java Thread.sleep方法代碼示例

本文整理匯總了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);
}
 
開發者ID:mbillig,項目名稱:RiskBots,代碼行數:17,代碼來源:RunGame.java

示例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());
}
 
開發者ID:casific,項目名稱:murmur,代碼行數:20,代碼來源:RangzenServiceTest.java

示例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");
}
 
開發者ID:alegen,項目名稱:netclip,代碼行數:18,代碼來源:Clipboard.java

示例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) {}
}
 
開發者ID:NCAR,項目名稱:dls-repository-stack,代碼行數:22,代碼來源:HarvestManager.java

示例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;
		}
	}
}
 
開發者ID:izvest,項目名稱:uni,代碼行數:22,代碼來源:Flappy.java

示例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);
}
 
開發者ID:theaigames,項目名稱:texasholdem-engine,代碼行數:21,代碼來源:TexasHoldem.java

示例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());
}
 
開發者ID:europeana,項目名稱:search,代碼行數:21,代碼來源:RTimer.java

示例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));
}
 
開發者ID:anhnv-3991,項目名稱:VoltDB,代碼行數:26,代碼來源:AsyncBenchmark.java

示例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);
}
 
開發者ID:theaigames,項目名稱:warlight2-engine,代碼行數:22,代碼來源:Warlight2.java

示例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) {

	}	
}
 
開發者ID:ethragur,項目名稱:SMRTMS,代碼行數:24,代碼來源:TokenHandlerTest.java

示例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){} 
       }

   }
 
開發者ID:jozadaquebatista,項目名稱:JAVA-Overview,代碼行數:19,代碼來源:threadAndRunnable.java

示例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");
}
 
開發者ID:Neraud,項目名稱:PADListener,代碼行數:22,代碼來源:Spider.java

示例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;
    }
}
 
開發者ID:Neraud,項目名稱:PADListener,代碼行數:22,代碼來源:Listener.java

示例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);
   }
 
開發者ID:danianr,項目名稱:quicket,代碼行數:17,代碼來源:SliceTest.java

示例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);
    }
}
 
開發者ID:TrilogisIT,項目名稱:FAO_Application,代碼行數:20,代碼來源:TiledRasterProducer.java


注:本文中的java.lang.Thread.sleep方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。