Results 1 to 5 of 5

Thread: What are an Executors in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    221

    What are an Executors in Java?

    Hi friends,
    I have recently completed with the basic functions of the threads. Now I have gone through the term executors of which I am having no idea. So thought to post here, as your help is very useful. So please tell me what are an Executors in Java? Hope that someone had got the point. Explain me as soon as possible.!!
    AMD Sempron 2800+ @ 2Ghz
    Asus A7V8X-LA
    120Gb Seagate barracuda 7200Rpm Ultra-ATA 100
    Elixir 512mb DDR Pc3200 (Soon 1Gb)
    Club 3D Radeon 9600 256Mb
    Lite-On Cd & Dvd writer combo
    IDE-Dvd drive
    400w Psu
    Windows Xp Pro Sp2
    Advent Wireless Mouse & Keyboard.

  2. #2
    Join Date
    Jul 2006
    Posts
    289

    Re: What are an Executors in Java?

    Normally close connection between the task being done by a new thread, as defined by its Runnable object, and the thread itself, as defined by a Thread object. In large-scale applications, it makes sense to separate thread management and creation from the rest of the application. Objects that encapsulate these functions are known as executors. An object that executes submitted Runnable tasks. An Executor interface does not strictly require that execution be asynchronous.
    Signatures reduce available bandwidth

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: What are an Executors in Java?

    The following subsections describe executors in detail :
    • Executor Interfaces define the three executor object types.
    • Thread Pools are the most common kind of executor implementation.

    The java.util.concurrent package defines three executor interfaces :
    1. Executor, a simple interface that supports launching new tasks.
    2. ExecutorService, a subinterface of Executor, which adds features that help manage the lifecycle, both of the individual tasks and of the executor itself.
    3. ScheduledExecutorService, a subinterface of ExecutorService, supports future and/or periodic execution of tasks.

  4. #4
    Join Date
    Mar 2008
    Posts
    672

    Re: What are an Executors in Java?

    The Executor interface provides a single method, execute, designed to be a drop-in replacement for a common thread-creation idiom. If r is a Runnable object, and e is an Executor object you can replace
    Code:
    (new Thread(r)).start();
    with the
    Code:
    e.execute(r);

  5. #5
    Join Date
    Nov 2008
    Posts
    1,192

    Re: What are an Executors in Java?

    The following is an example of Executors in coding :
    Code:
    import java.io.IOException;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.concurrent.TimeUnit;
    
    public class ClassDemo {
      ExecutorService executor = Executors.newFixedThreadPool(3);
    
      public void start() throws IOException {
        int i=0;
        while (!executor.isShutdown())
          executor.submit(new MyThread(i++));
      }
    
      public void shutdown() throws InterruptedException {
        executor.shutdown();
        executor.awaitTermination(30, TimeUnit.SECONDS);
        executor.shutdownNow();
      }
    
      public static void main(String argv[]) throws Exception {
        new ClassDemo().start();
      }
    }
    
    class MyThread implements Runnable {
    private int i;
      MyThread(int i) {
      this.i = i;
      }
    
      public void run() {
        System.out.println("I am in thread:"+i);
        
      }
    }

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. Comparison between core java and advanced java
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 10:57 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,460,798.35636 seconds with 17 queries