{"id":79262,"date":"2020-06-30T09:00:25","date_gmt":"2020-06-30T03:30:25","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79262"},"modified":"2020-06-30T09:00:25","modified_gmt":"2020-06-30T03:30:25","slug":"java-executorservice","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/","title":{"rendered":"ExecutorService in Java &#8211; Java ExecutorService Examples"},"content":{"rendered":"<p>In this <strong>TechVidvan Java tutorial,<\/strong> we will learn about the <strong>executorservice in Java<\/strong>. We already know that Java works very efficiently with multithreaded applications that require to execute the tasks concurrently in a thread.<\/p>\n<p>It is challenging for any application to execute a large number of threads simultaneously. Thus, to overcome this problem, Java provides the ExecutorService interface, which is a sub-interface of the Executors framework.<\/p>\n<p>In this article, we will understand how to create an ExecutorService. And, how to submit tasks for execution to executor service, We also discuss how we can see the results of those tasks.<\/p>\n<p>At last, we will study how to shut down the ExecutorService again when required.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Executor-Service-in-java-tv.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-79279 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Executor-Service-in-java-tv.jpg\" alt=\"Executor Service in java\" width=\"1200\" height=\"628\" \/><\/a><\/p>\n<h3>What is the Executor Framework?<\/h3>\n<p>It is easier for us to create and execute one or two threads simultaneously. But when the number of threads increases to a significant number, it becomes difficult. Many multi-threaded applications have hundreds of threads running simultaneously.<\/p>\n<p>Therefore, there is a need to separate the creation of the thread from the management of thread in an application.<\/p>\n<p>The Java ExecutorService interface is in the java.util.concurrent package. This interface represents an asynchronous execution mechanism to execute several tasks concurrently in the background.<\/p>\n<h3>Tasks performed by ExecutorService<\/h3>\n<p>The executor service framework helps in creating and managing threads in an application. The executor framework performs the following tasks.<\/p>\n<p><strong>1. Thread Creation:<\/strong> Executor service provides many methods for the creation of threads. This helps in running applications concurrently.<\/p>\n<p><strong>2. Thread Management:<\/strong> Executor service also helps in managing the thread life cycle. We need not worry if the thread is in the active, busy, or dead state before submitting the task for execution.<\/p>\n<p><strong>3. Task Submission And Execution:<\/strong> Executor framework also provides methods to submit tasks in the thread pool. It also provides the power to decide whether the thread will execute or not.<\/p>\n<h3>Task Delegation<\/h3>\n<p>The below diagram represents a thread delegating a task to a Java ExecutorService for asynchronous execution:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Task-Delegation.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79280\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/Task-Delegation.jpg\" alt=\"Task Delegation in Java\" width=\"609\" height=\"453\" \/><\/a><\/p>\n<h3>Creating an ExecutorService<\/h3>\n<p>ExecutorService is an interface in Java. The implementations of this interface can execute a Runnable or Callable class in an asynchronous way. We have to note that invoking the run() method of a Runnable interface in a synchronous way is calling a method.<\/p>\n<p>We can create an instance of ExecutorService interface in the following ways:<\/p>\n<h4>1. Executors class<\/h4>\n<p>Executors class is a utility class that provides factory methods to create the implementations of the Executor service interface.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">\/\/Executes only one thread\nExecutorService es = Executors.newSingleThreadExecutor();\n\n\/\/Internal management of thread pool of 2 threads\nExecutorService es = Executors.newFixedThreadPool(2);\n\n\/\/Internally managed thread pool of 10 threads to run scheduled tasks\nExecutorService es = Executors.newScheduledThreadPool(10);<\/pre>\n<h4>2. Constructors<\/h4>\n<p>The below statement creates a thread pool executor. We create it using the constructors with minimum thread count 10. The maximum thread count is 100. The keepalive time is five milliseconds. And, there is a blocking queue to watch for tasks in the future.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.util.concurrent.ExecutorService;\nimport java.util.concurrent.ThreadPoolExecutor;\nimport java.util.concurrent.TimeUnit;\nimport java.util.concurrent.LinkedBlockingQueue;\nExecutorService exService = new ThreadPoolExecutor(10, 100, 5L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue &lt; Runnable &gt; ());<\/pre>\n<h3>Example of ExecutorService in Java<\/h3>\n<p>The ExecutorService in Java is a subinterface of the executor framework. It provides certain functions to manage the thread life cycle of an application. There is also a submit() method that can accept both runnable and callable objects.<\/p>\n<p>In the below example, we will create an ExecutorService with a single thread and then submit the task to be executed inside the thread.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import java.util.concurrent.ExecutorService;\nimport java.util.concurrent.Executors;\npublic class Example {\n  public static void main(String[] args) {\n    System.out.println(\"Inside: \" + Thread.currentThread().getName());\n    System.out.println(\"Creating ExecutorService\");\n    ExecutorService executorservice = Executors.newSingleThreadExecutor();\n    System.out.println(\"Creating a Runnable\");\n    Runnable runnable = () - &gt;{\n      System.out.println(\"Inside: \" + Thread.currentThread().getName());\n    };\n    System.out.println(\"Submitting the task specified by the runnable to the executorservice\");\n    executorservice.submit(runnable);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Inside: main<br \/>\nCreating ExecutorService<br \/>\nCreating a Runnable<br \/>\nSubmitting the task specified by the runnable to the executorservice<br \/>\nInside: pool-1-thread-1<\/div>\n<p><em><strong>Note:<\/strong><\/em> When you run the above program, the program will never exit. You will need to shut it down explicitly since the executor service keeps listening for new tasks.<\/p>\n<h3>Java ExecutorService Implementations<\/h3>\n<p>ExecutorService is very similar to the thread pool. The implementation of the ExecutorService in the java.util.concurrent package is a thread pool implementation. There are following implementations of ExecutorService in the java.util.concurrent package:<\/p>\n<h4>1. ThreadPoolExecutor<\/h4>\n<p>The ThreadPoolExecutor executes the specified tasks using one of its internally pooled threads.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/ThreadPoolExecutor.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79281\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/ThreadPoolExecutor.jpg\" alt=\"Thread Pool Executor in Java\" width=\"701\" height=\"410\" \/><\/a><\/p>\n<p><strong>Creating a threadPoolExecutor<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">int corethreadPoolSize = 10;\nint maxPoolSize = 15;\nlong keepAliveTime = 6000;\nExecutorService es = new threadPoolExecutor(corethreadPoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue &lt; Runnable &gt; ());<\/pre>\n<h4>2. ScheduledThreadPoolExecutor<\/h4>\n<p>The ScheduledThreadPoolExecutor is an ExecutorService that can schedule tasks to run after a delay or to execute repeatedly with a fixed interval of time in between each execution.<\/p>\n<p><strong>Creating a ScheduledthreadPoolExecutor<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">ScheduledExecutorService scheduledexecutorservice = Executors.newScheduledThreadPool(5);\nScheduledFuture scheduledfuture = scheduledExecutorService.schedule(new Callable() {\n  public Object call() throws Exception {\n    System.out.println(\"executed\");\n    return \"called\";\n  }\n},\n5, TimeUnit.SECONDS);<\/pre>\n<h3>ExecutorService Usage in Java<\/h3>\n<p>The following are the different ways to delegate tasks for execution to an ExecutorService:<\/p>\n<ul>\n<li>execute(Runnable)<\/li>\n<li>submit(Runnable)<\/li>\n<li>submit(Callable)<\/li>\n<li>invokeAny(&#8230;)<\/li>\n<li>invokeAll(&#8230;)<\/li>\n<\/ul>\n<h3>1. Execute Runnable in java<\/h3>\n<p>The ExecutorService execute(Runnable) method of Java takes an object of Runnable and executes it asynchronously.<\/p>\n<p><strong>Below is an example of executing a Runnable with an ExecutorService:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">ExecutorService executorService = Executors.newSingleThreadExecutor();\nexecutorService.execute(new Runnable() {\n  public void run() {\n    System.out.println(\"asynchronous task\");\n  }\n});\nexecutorService.shutdown();<\/pre>\n<h4>2. Submit Runnable in java<\/h4>\n<p>The submit(Runnable) method takes a Runnable implementation and returns a Future object. We can use this Future object to check if the Runnable has finished executing.<\/p>\n<p><strong>Here is a Java ExecutorService submit() example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Future future = executorService.submit(new Runnable() {\n  public void run() {\n    System.out.println(\" asynchronous task \");\n}\n});\nfuture.get();<\/pre>\n<h4>3. Submit Callable in Java<\/h4>\n<p>The Java submit(Callable) method is similar to the submit(Runnable) method except it takes a Callable object instead of a Runnable. We can obtain the Callable&#8217;s result using the Java Future object returned by the submit(Callable) method.<\/p>\n<p><strong>Here is an ExecutorService Callable example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Future future = executorService.submit(new Callable() {\n  public Object call() throws Exception {\n    System.out.println(\"Asynchronous callable\");\n    return \"Callable Result\";\n  }\n});\nSystem.out.println(\"future.get() = \"\nfuture.get());<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Asynchroous callable<br \/>\nfuture.get = Callable Result<\/div>\n<h4>4. invokeAny() in java<\/h4>\n<p>The invokeAny() method takes a collection or subinterfaces of Callable objects. This method returns the result of one of the Callable objects. There is no guarantee about which of the Callable results we will get.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class ExecutorServiceExample {\n  public static void main(String[] args) throws ExecutionException,\n  InterruptedException {\n    ExecutorService es = Executors.newSingleThreadExecutor();\n    Set &lt; Callable &lt; String &gt;&gt; callable = new HashSet &lt; Callable &lt; String &gt;&gt; ();\n    callable.add(new Callable &lt; String &gt; () {\n      public String call() throws Exception {\n        return \"Task 1\";\n      }\n    });\n    callable.add(new Callable &lt; String &gt; () {\n      public String call() throws Exception {\n        return \"Task 2\";\n      }\n    });\n    callable.add(new Callable &lt; String &gt; () {\n      public String call() throws Exception {\n        return \"Task 3\";\n      }\n    });\n    String result = es.invokeAny(callable);\n    System.out.println(\"result = \" + result);\n    executorService.shutdown();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">result = Task 1<\/div>\n<h4>5. invokeAll() in Java<\/h4>\n<p>The invokeAll() method invokes all of the objects of Callable that we pass to it in the collection as parameters. This method returns a list of Future objects through which we can obtain the results of the executions of each Callable.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class ExecutorServiceExample {\n  public static void main(String[] args) throws InterruptedException,\n  ExecutionException {\n    ExecutorService executorService = Executors.newSingleThreadExecutor();\n    Set &lt; Callable &lt; String &gt;&gt; callable = new HashSet &lt; Callable &lt; String &gt;&gt; ();\n    callable.add(new Callable &lt; String &gt; () {\n      public String call() throws Exception {\n        return \"Task 1\";\n      }\n    });\n    callable.add(new Callable &lt; String &gt; () {\n      public String call() throws Exception {\n        return \"Task 2\";\n      }\n    });\n    callable.add(new Callable &lt; String &gt; () {\n      public String call() throws Exception {\n        return \"Task 3\";\n      }\n    });\n    java.util.List &lt; Future &lt; String &gt;&gt; futures = executorService.invokeAll(callable);\n\n    for (Future &lt; String &gt; future: futures) {\n      System.out.println(\"future.get = \" + future.get());\n    }\n    executorService.shutdown();\n\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">future.get = Task 1<br \/>\nfuture.get = Task 3<br \/>\nfuture.get = Task 2<\/div>\n<h3>ExecutorService Shutdown in Java<\/h3>\n<p>When we compete using the Java ExecutorService we should shut it down, so the threads do not keep running. There are some situations when start an application via a main() method and the main thread exits our application.<\/p>\n<p>In such cases, the application will keep running if there is an active ExecutorService in the application. These active threads present inside the ExecutorService prevents the JVM from shutting down.<\/p>\n<p>Let&#8217;s discuss the methods to shut down an Executor service:<\/p>\n<h4>1. shutdown() in Java<\/h4>\n<p>We call the shutdown() method to terminate the threads inside the ExecutorService. This does not shut down the ExecutorService immediately, but it will no longer accept new tasks.<\/p>\n<p>Once all the threads finish their current tasks, the ExecutorService shuts down. Before we call the shutdown() all tasks submitted to the ExecutorService are executed.<\/p>\n<p>Below is an example of performing a Java ExecutorService shutdown:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">executorService.shutdown();<\/pre>\n<h4>2. shutdownNow() in Java<\/h4>\n<p>If we need to shut down the ExecutorService immediately, we can call the shutdownNow() method. This method will attempt to stop all executing tasks right away, and skip all the submitted but non-processed tasks.<\/p>\n<p>But, there will be no guarantee about the executing tasks. They may either stop or may execute until the end.<\/p>\n<p>For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">executorService.shutdownNow();\n<\/pre>\n<h4>3. awaitTermination() in Java<\/h4>\n<p>The ExecutorService awaitTermination() method blocks the thread calling it until either the ExecutorService has shutdown completely, or until a given time out occurs. The awaitTermination() method is typically called after calling shutdown() or shutdownNow().<\/p>\n<p>Below is an example of calling ExecutorService awaitTermination() method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">executorService.awaitTermination();<\/pre>\n<h3>Runnable vs. Callable Interface in Java<\/h3>\n<p>The Runnable interface is almost similar to the Callable interface. Both Runnable and Callable interfaces represent a task that a thread or an ExecutorService can execute concurrently. There is a single method in both interfaces.<\/p>\n<p>There is one small difference between the Runnable and Callable interface. The difference between both the interfaces is clearly visible when we see the interface declarations.<\/p>\n<p>Here is declaration of the Runnable interface:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public interface Runnable {\n  public void run();\n}<\/pre>\n<p>Here is declaration of the Callable interface:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public interface Callable {\n  public Object call() throws Exception;\n}<\/pre>\n<p>The main difference between the run() method of Runnable and the call() method of Callable is that call() can throw an exception, whereas run() cannot throw an exception, except the unchecked exceptions &#8211; subclasses of RuntimeException.<\/p>\n<p>Another difference between call() and run() is that the call() method can return an Object from the method call.<\/p>\n<h3>Cancelling Task in Java<\/h3>\n<p>We can also cancel a Runnable or Callable task submitted to the ExecutorService of Java. We can cancel the task by calling the cancel() method on the Future. It is possible to cancel the task only if the task has not yet started executing.<\/p>\n<p>For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Future.cancel();<\/pre>\n<h3>Conclusion<\/h3>\n<p>Finally we saw ExecutorService helps in minimizing the complex code. It also helps in managing the resources by internally utilizing a thread pool. Programmers should be careful to avoid some common mistakes.<\/p>\n<p>For example, always shutting down the executor service after the completion of tasks and services that are no longer needed. Otherwise, JVM will never terminate, normally. In this tutorial, we covered each and every concept of Executor service in Java.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this TechVidvan Java tutorial, we will learn about the executorservice in Java. We already know that Java works very efficiently with multithreaded applications that require to execute the tasks concurrently in a thread.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79279,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2964,2965,2966,2967,2968],"class_list":["post-79262","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-executorservice","tag-executorservice-example","tag-executorservice-in-java","tag-java-executor-service","tag-java-executorservice-example"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ExecutorService in Java - Java ExecutorService Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn what is ExecutorService in Java and their tasks, ExecutorService implementation &amp; examples, Executor Framework, Creating ExecutorService and its Usage\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ExecutorService in Java - Java ExecutorService Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn what is ExecutorService in Java and their tasks, ExecutorService implementation &amp; examples, Executor Framework, Creating ExecutorService and its Usage\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-30T03:30:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Executor-Service-in-java-tv.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ExecutorService in Java - Java ExecutorService Examples - TechVidvan","description":"Learn what is ExecutorService in Java and their tasks, ExecutorService implementation & examples, Executor Framework, Creating ExecutorService and its Usage","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/","og_locale":"en_US","og_type":"article","og_title":"ExecutorService in Java - Java ExecutorService Examples - TechVidvan","og_description":"Learn what is ExecutorService in Java and their tasks, ExecutorService implementation & examples, Executor Framework, Creating ExecutorService and its Usage","og_url":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-30T03:30:25+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Executor-Service-in-java-tv.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"ExecutorService in Java &#8211; Java ExecutorService Examples","datePublished":"2020-06-30T03:30:25+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/"},"wordCount":1422,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Executor-Service-in-java-tv.jpg","keywords":["executorservice","executorservice example","ExecutorService in Java","java executor service","java executorservice example"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/","url":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/","name":"ExecutorService in Java - Java ExecutorService Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Executor-Service-in-java-tv.jpg","datePublished":"2020-06-30T03:30:25+00:00","description":"Learn what is ExecutorService in Java and their tasks, ExecutorService implementation & examples, Executor Framework, Creating ExecutorService and its Usage","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-executorservice\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Executor-Service-in-java-tv.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Executor-Service-in-java-tv.jpg","width":1200,"height":628,"caption":"Executor Service in java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-executorservice\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"ExecutorService in Java &#8211; Java ExecutorService Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79262"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79262\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79279"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}