A
ankur
Hi, I thought all methods in interfaces are public abstract i.e. they
are not implemented in the interface definition but are supposed to be
implemented by the class implementing the interface. So I was
wondering how come the methods for ExecutorService and Executor
interfaces are defined already ( or are they ?? ).
For e.g. how is this code able to call execute() ??
public class RunnableTester
{
public static void main( String[] args )
{
// create and name each runnable
PrintTask task1 = new PrintTask( "thread1" );
PrintTask task2 = new PrintTask( "thread2" );
System.out.println( "Starting threads" );
// create ExecutorService to manage
threads
ExecutorService threadExecutor =
Executors.newFixedThreadPool(2);
// start threads and place in runnable state
threadExecutor.execute( task1 ); // start task1
threadExecutor.execute( task2 ); // start task2
threadExecutor.shutdown(); // shutdown worker threads
System.out.println( "Threads started, main ends\n" );
} // end main
} // end class RunnableTester
I know Executors class returns an ExecutorService but where is the
method execute() implemented ? Similarly where are the methods in
ExecutorService like shutdown() and shutdownnow() implemented ?
Ankur
are not implemented in the interface definition but are supposed to be
implemented by the class implementing the interface. So I was
wondering how come the methods for ExecutorService and Executor
interfaces are defined already ( or are they ?? ).
For e.g. how is this code able to call execute() ??
public class RunnableTester
{
public static void main( String[] args )
{
// create and name each runnable
PrintTask task1 = new PrintTask( "thread1" );
PrintTask task2 = new PrintTask( "thread2" );
System.out.println( "Starting threads" );
// create ExecutorService to manage
threads
ExecutorService threadExecutor =
Executors.newFixedThreadPool(2);
// start threads and place in runnable state
threadExecutor.execute( task1 ); // start task1
threadExecutor.execute( task2 ); // start task2
threadExecutor.shutdown(); // shutdown worker threads
System.out.println( "Threads started, main ends\n" );
} // end main
} // end class RunnableTester
I know Executors class returns an ExecutorService but where is the
method execute() implemented ? Similarly where are the methods in
ExecutorService like shutdown() and shutdownnow() implemented ?
Ankur