Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Threads
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Threads and Synchronization
Executor Interface
meeta gaur
Ranch Hand
Posts: 305
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Executor Implementation
import java.util.concurrent.Executor; class ExecutorExample1 implements Runnable,Executor { public void run(){ System.out.println(Thread.currentThread().getName()); } public void execute(Runnable r){ Thread t1=new Thread(r); Thread t2=new Thread(r); t1.setName("t1"); t2.setName("t2"); t1.start(); t2.start(); } public static void main(String[] args) { ExecutorExample1 obj=new ExecutorExample1(); obj.execute(obj); } }
t1
t2
Withou Executor Implementation
import java.util.concurrent.Executor; class ExecutorExample1 implements Runnable { public void run(){ System.out.println(Thread.currentThread().getName()); } public void execute(Runnable r){ Thread t1=new Thread(r); Thread t2=new Thread(r); t1.setName("t1"); t2.setName("t2"); t1.start(); t2.start(); } public static void main(String[] args) { ExecutorExample1 obj=new ExecutorExample1(); obj.execute(obj); } }
t1
t2
I don't understand use of Executor.In both cases same output, then why will anyone implement this ?
My one regret in life is that I am not someone else.
- Woody Allen
meeta gaur
Ranch Hand
Posts: 305
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Oh, got it.I didn't use implementer class.
My one regret in life is that I am not someone else.
- Woody Allen
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Thread doubt
Confusion in threads
ThreadGroup question
How to make one thread die before another thread
More...