Java 8 Thread - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Thread class.

This code example shows how to use the following methods:getContentResolver, getFilesDir, openFileOutput, sendBroadcast, sleep
                    "dfrsRsFMrFpk++mSt6SoxXaMbn0LL2u1CD4PCEiQMGt+lK3/3TmRTKNs+23sYS7Ahjxj0udDAkEA" + 
                    "p57Nj65WNaWeYiOfTwKXkLj8l29H5NbaGWxPT0XkWr4PvBOFZVH/wj0/qc3CMVGnv11+DyO+QUCN" + 
                    "SqBB5aRe8g=="; 
 
    private void overrideSettings(String key, String value) throws Exception {
        assertTrue(Settings.Secure.putString(mContext.getContentResolver(), key, value));
        Thread.sleep(1000);
    } 
 
    private void overrideCert(String value) throws Exception {
        overrideSettings(PINLIST_CERTIFICATE_KEY, value);
    } 
 
    private String readPins() throws Exception {
        return IoUtils.readFileAsString(PINLIST_CONTENT_PATH);
    } 
 
    private String readCurrentVersion() throws Exception {
        return IoUtils.readFileAsString("/data/misc/keychain/metadata/version"); 
    } 

9
CodeRank
This code example shows how to use the following methods:sleep, get
            stateSequencer.advance("t1:s1", 10, SECONDS); 
            return null; 
         } 
      }); 
 
      final AtomicBoolean t2s2Entered = new AtomicBoolean(false);
      Future<Object> future2 = fork(new Callable<Object>() {
         @Override 
         public Object call() throws Exception { 
            stateSequencer.enter("t2:s2", 10, SECONDS); 
            t2s2Entered.set(true); 
            stateSequencer.exit("t2:s2"); 
            return null; 
         } 
      }); 
 
      stateSequencer.enter("start", 0, SECONDS);
      Thread.sleep(500);
      assertFalse(future1.isDone()); 
      assertFalse(future2.isDone()); 

9
CodeRank
This code example shows how to use the following methods:close, getFD, write, sleep
    Random random = new Random();
    byte[] data = new byte[size];
    random.nextBytes(data);
 
    newFile.createNewFile();
    RandomAccessFile file = new RandomAccessFile(newFile, "rws");
 
    file.write(data);
       
    file.getFD().sync();
    file.close();
  } 
 
  /** 
   * Verify that du returns expected used space for a file. 
   * We assume here that if a file system crates a file of size  
   * that is a multiple of the block size in this file system, 
   * then the used size for the file will be exactly that size. 
   * This is true for most file systems. 
   *  

9
CodeRank
This code example shows how to use the following methods:close, readLine, sleep
		try { 
			logger.debug("KeyValueStore waiting for clients...");	 
			Socket clientSocket = serverSocket.accept();
			logger.debug("KeyValueStore client connected..."); 
			BufferedWriter os = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
			BufferedReader is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			String input = is.readLine();
			logger.debug("KeyValueStore received input: {}", input);
			if (input.split("\\s+").length == 2) {
				input = input.split("\\s+")[1];	// "GET deft" => "deft"
			} 
			int sleep = 250;
			if (input != null) {
				logger.debug("KeyValueStore server sleeps " + sleep + "ms..." );
				try { 
					Thread.sleep(sleep);
				} catch (InterruptedException e) {
					e.printStackTrace();
				} 
				logger.debug("KeyValueStore woke up..."); 

8
CodeRank
This code example shows how to use the following methods:getFileDescriptor, getLength, getStartOffset, sleep
    //Load midi file from resources 
    public static boolean resourcesPlayback(AssetFileDescriptor afd, int expectedDuration){
        int duration = 0;
        try{ 
            MediaPlayer mp = new MediaPlayer();
            mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
            mp.prepare();
            mp.start();
            duration = mp.getDuration();
            Thread.sleep(5000);
            mp.release();
        }catch (Exception e){
            Log.v(TAG,e.getMessage());
        } 
        if (duration > expectedDuration)
            return true; 
        else 
            return false; 
    } 
 
8
CodeRank
This code example shows how to use the following methods:sleep, close, getBean, start, stop
		super(); 
	} 
 
	public static void main(String args[]) throws Exception {
 
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        		new String[] {"client-context.xml"});
 
        // By starting the context consumer-side endpoint, that receives 
        // callback messages, is started 
        context.start();
 
        // Here request-callback request to the service provider is performed 
        context.getBean("tester");
         
        Thread.sleep(120000);
 
        context.stop();
        context.close();
        System.exit(0);

8
CodeRank
This code example shows how to use the following methods:set, sleep
 
        Canvas c = null;
        if (onAllowLockCanvas()) { 
            if (dirty == null) {
                if (mTmpDirty == null) {
                    mTmpDirty = new Rect();
                } 
                mTmpDirty.set(mSurfaceFrame);
                dirty = mTmpDirty;
            } 
 
            try { 
                c = mSurface.lockCanvas(dirty);
            } catch (Exception e) {
                Log.e(TAG, "Exception locking surface", e);
            } 
        } 
 
        if (DEBUG) Log.i(TAG, "Returned canvas: " + c);
        if (c != null) {

8
CodeRank
This code example shows how to use the following methods:sleep
 
        // check that the connector is live 
        String cURL = "http://" + url.getHost() + ":8181";
 
        //this tests for default content serving... 
        String response = HttpRequest.get(cURL, 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("JBoss") >=0);
 
 
        // remove connector 
        cli.sendLine("/subsystem=undertow/server=default-server/http-listener=test-listener:remove{allow-resource-service-restart=true}"); 
        result = cli.readAllAsOpResult();
        assertTrue(result.isIsOutcomeSuccess());
 
        cli.sendLine("/socket-binding-group=standard-sockets/socket-binding=test:remove"); 
        result = cli.readAllAsOpResult();
        assertTrue(result.isIsOutcomeSuccess());
 
        // check that the connector is no longer live 
        Thread.sleep(5000);

8
CodeRank
This code example shows how to use the following methods:close, readLine, sleep
        try { 
            URL url = new URL("http://localhost:9003/Application/writeChunks2");
            URLConnection connection = url.openConnection();
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line = reader.readLine();
            if (line != null)
                result = line.trim();
        } 
        catch (IOException e) {
        } 
        finally { 
            if (reader != null) {
                try { 
                    reader.close();
                } 
                catch (IOException e) {
                } 
            } 

8
CodeRank
This code example shows how to use the following methods:sleep, await, countDown
    */ 
   @Test 
   public void testTimeout() throws Exception 
   { 
      // we use a countdown latch for the 2 threads involved 
      CountDownLatch latch = new CountDownLatch(2);
      // get a write lock 
      Lock writeLock = this.ejbReadWriteLock.writeLock();
      // create a thread which will get hold of a write lock  
      // and do some processing for 5 seconds 
      Thread threadHoldingWriteLock = new Thread(new ThreadHoldingWriteLock(latch, writeLock, 5000));
       
      // get a read lock 
      Lock readLock = this.ejbReadWriteLock.readLock();
       
      // start the write lock thread (which internally will obtain  
      // a write lock and start a 5 second processing) 
      threadHoldingWriteLock.start();
      // wait for few milli sec for the write lock thread to obtain a write lock 
      Thread.sleep(500);

8
CodeRank

Related Java 8 Thread Questions & Answers:

See Code Examples for Java 8 Thread Methods: