android - What is callable in Java? -


The title tells too much

I want to know the idea of ​​sensible and concept. I have read on the difference between colebal and runnabal but no code shows and explains in detail that what a callable person is. I do not want to know the difference between them. I want to know,

  1. What is a collage?

  2. When to use them and how to use them

  3. When they take action for Android

    You can check it out:

    In this example, callable function returns the name of the executed thread after one second. We are using the excercise framework to execute 100 operations parallel and use the future to get the results of the work presented.

      package com.journaldev.threads; Import java.util.ArrayList; Import java.util.Date; Import java.util.list; Import java.util.concurrent.Callable; Import java.util.concurrent.ExecutionException; Import java.util.concurrent.ExecutorService; Import java.util.concurrent.Executors; Import java.util.concurrent.Future; Public Class Microwaveable Tools Callable & lt; String & gt; {@ Override public string call ()) Exception {Thread.sleep (1000); Return this thread to the name of the thread that performs this callable job returns. Concert (). GetName (); } Public stable Zero Main (string algos []) {// Obtain executable service from executable utility class, Thread Pool Size 10 Executable Service Executor = Exporter NewfixedThreadPool (10); // Create a list to capture the future object with a callable list & lt; Future & lt; String & gt; & Gt; List = New Arrestist & lt; Future & lt; String & gt; & Gt; (); // Create MyCallable Image Collage & lt; String & gt; Collage = New MyCallable (); For (Int i = 0; i & lt; 100; i ++) {// Present the callable task executable by a Thread Pool; In the future, & lt; String & gt; Future = executor submit (callable); // Add a future to the list, we can get return value using the future list.add (future); } (Future & lt; String & gt; fut: list) {Try / Print the return value of the future, note the delay in the output in the console / / because Future.Gate () has been completed, System. Out.printeline (new date) + "::" + fut.get ()); } Hold (interrupted) exception. Execution Exception e) {e.printStackTrace (); }} // Now shutting down the Execution Service. Executor shut down (); }}   

    You can also check

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -