Brief
1. A thread can be created either by implementing "Runnable" interface or extending "Thread" class
Inside difference
Thread class internally Implements Runnable interface
and overrides "run" method.
when you call
Thread t = new thread(Runnnable r); --> sets global variable Runnable target = r;
t.start() --> this thread method in Thread class, internally calls local run() and that run method called
target.run().
So if runnable is passed as target, then the class which implements this Runnable.run() will be invoked.
If its thread class is extended , then this target is set as extending class's instance, hence it becames target in run() of thread class.
1. A thread can be created either by implementing "Runnable" interface or extending "Thread" class
Inside difference
Thread class internally Implements Runnable interface
and overrides "run" method.
when you call
Thread t = new thread(Runnnable r); --> sets global variable Runnable target = r;
t.start() --> this thread method in Thread class, internally calls local run() and that run method called
target.run().
So if runnable is passed as target, then the class which implements this Runnable.run() will be invoked.
If its thread class is extended , then this target is set as extending class's instance, hence it becames target in run() of thread class.
On Synchronization
No comments:
Post a Comment