tag:blogger.com,1999:blog-8712770457197348465.post8129718066904212277..comments2024-03-18T23:01:42.768-07:00Comments on Javarevisited: Difference between Thread vs Runnable interface in Javajavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-8712770457197348465.post-31418687804798697042019-11-05T05:29:33.701-08:002019-11-05T05:29:33.701-08:00Hello Divya, this means you can create many object...Hello Divya, this means you can create many object of same Runnable class and reuse them to run with multiple threads like a thread pool. A good example is RecursiveTask on ForkJoinPoool API. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10094188393587026792019-11-04T03:52:04.920-08:002019-11-04T03:52:04.920-08:00Can you explain 4th point with example please?Can you explain 4th point with example please?Divyahttps://www.blogger.com/profile/11165428646333372836noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-18228356969976187502016-12-08T17:10:29.514-08:002016-12-08T17:10:29.514-08:00@Anonymous, thanks, I'll think about it btw yo...@Anonymous, thanks, I'll think about it btw you can post question as comments for nowjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-78935926673048609102016-12-07T13:26:53.668-08:002016-12-07T13:26:53.668-08:00I always used to save this Links of your articles ...I always used to save this Links of your articles from facebook it self <br /><br />Thanks for the all articles as well as your efforts to teach us a better java ..<br /><br />Request you to open a questions and answers form...when we can ask any doubt if we face .<br /><br />Thanks in advanceAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-86789547386269844782016-11-05T09:39:30.217-07:002016-11-05T09:39:30.217-07:00why we create object of thread class inside main w...why we create object of thread class inside main when we created thread using implementing runnable. plz explain.Anonymoushttps://www.blogger.com/profile/06282506544648489902noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-90475577117724313762016-05-08T11:15:37.699-07:002016-05-08T11:15:37.699-07:00Hi plz assist in which scenario thread class using...Hi plz assist in which scenario thread class using is better then runnable<br />Anonymoushttps://www.blogger.com/profile/15648312511876592237noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-79957562828588078312016-01-18T04:11:32.871-08:002016-01-18T04:11:32.871-08:00@Deepak
class GUI extends Canvas implements Runna...@Deepak<br /><br />class GUI extends Canvas implements Runnable{<br /> // do whatever you want to do<br />}javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-56825827747664555692016-01-17T21:23:03.494-08:002016-01-17T21:23:03.494-08:00please show some coding examples on how we can ext...please show some coding examples on how we can extend another class while implementing Runnable.Anonymoushttps://www.blogger.com/profile/09755506092759398408noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-70725948693079904852015-02-19T23:05:10.179-08:002015-02-19T23:05:10.179-08:00For creating Thread why we have two ways of creati...For creating Thread why we have two ways of creation. Implementing Runnable is best then why do we need "Thread" class ??Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-64022882593576659192014-07-18T18:48:34.776-07:002014-07-18T18:48:34.776-07:00Hello Anonymous, By using Runnable, you can pass s...Hello Anonymous, By using Runnable, you can pass same task to multiple thread as different instance of Runnable, this way you can reuse the code, If you were to do the same, you have to create different instances of thread, which would be costly. In earlier case, you can reuse those threads.Saumyanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-90101204300547308012014-07-18T13:49:09.971-07:002014-07-18T13:49:09.971-07:00I didn't understand the 4th point in differenc...I didn't understand the 4th point in difference..by implementing Runnable interface how u can can reuse the task...how Runnable is winner can u plz elaborate Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-91222643467566875982014-06-04T21:45:50.025-07:002014-06-04T21:45:50.025-07:00when should we use Runnable interface instead of T...when should we use Runnable interface instead of Thread. Give logic apart from multiple inheritence in javaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69622736969692952642013-09-24T08:26:34.544-07:002013-09-24T08:26:34.544-07:00Everybody talks about Thread vs Runnable stuff an...Everybody talks about Thread vs Runnable stuff and suggests the coders to use Runnable interface for obvious reasons but I'm really interested about the reason behind allowing the Thread class to be extended. for most of the applications its very unlikely that we change the behavior of thread by extending the Thread class. They could have made the Thread class final just like how they did manjuhttps://www.blogger.com/profile/15151192967134772305noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-38156866588405246492013-07-11T22:49:32.778-07:002013-07-11T22:49:32.778-07:00another difference of Thread V/S Runnable is
Use ...another difference of Thread V/S Runnable is<br /><br />Use Runnable interface when you want to access the same resource from the group of threads. Avoid using Thread class here, because multiple objects creation consumes more memory and it becomes a big performance overhead.Anonymoushttps://www.blogger.com/profile/09217987121224857067noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-51461863015898588172013-04-19T07:59:34.045-07:002013-04-19T07:59:34.045-07:00Javin. A doubt related to interface. Why a data me...Javin. A doubt related to interface. Why a data member in an interface implicitly final?<br />-HareshKannanAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-54480586571665956552013-04-12T23:07:04.625-07:002013-04-12T23:07:04.625-07:00Hi Javin...nice article few things that I want to ...Hi Javin...nice article few things that I want to add in this is ..Yes,implements Runnable is the preferred way to do it, as You're not really specialising the thread's behaviour. You're just giving it something to run. That means composition is the philosophically "purer" way to go.<br /><br />In general, I would recommend using something like Runnable rather than Thread SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-78541411016573784362013-03-21T00:37:39.599-07:002013-03-21T00:37:39.599-07:00@Anonymous, There is big difference, When you exte...@Anonymous, There is big difference, When you extend java.lang.Thread to run your task (code inside run() method) in another thread, you actually create a full Thread class, while implementing Runnable is just a wrapper around your task, so that it can be executed by individual threads or worker threads inside a Thread pool.<br /><br />In short Runnable is cheap.Javin @ Connection refused exception in Javahttp://javarevisited.blogspot.com/2013/02/java-net-ConnectException-Connection-refused.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-34879864417864564092013-03-18T07:52:21.136-07:002013-03-18T07:52:21.136-07:00Thanks for nice article @Javin, still I have some ...Thanks for nice article @Javin, still I have some doubts regarding overhead we face when extends thread<br /><br />While extend thread class your class will have all functionalists of thread, same way when you creating thread using runnable interface, you need to pass this object to thread class.<br />So that object again have all functionalists of thread.<br /><br />Could you please help me on Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-84415946904958622632012-12-12T04:05:52.609-08:002012-12-12T04:05:52.609-08:00Hi Javin,
Generally, I read stuff from blogs and d...Hi Javin,<br />Generally, I read stuff from blogs and don't bother to comment on any. But your topics are so well explained, I couldn't ignore commenting on how nice your articles are..<br />You did a very good job!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-55776206967221775222012-09-12T20:24:32.551-07:002012-09-12T20:24:32.551-07:00I think most important difference between Thread a...I think most important difference between Thread and Runnable in Java is that Thread is a Class and Runnable is a interface. isn't it ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-81043559115891608792012-07-30T14:27:11.744-07:002012-07-30T14:27:11.744-07:00good article thnxgood article thnxAnonymoushttps://www.blogger.com/profile/13470993061518904531noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-69859654262064428232012-05-20T23:27:35.581-07:002012-05-20T23:27:35.581-07:00Its not that difficult to choose between Runnable ...Its not that difficult to choose between Runnable and Thread than Callable and Runnable for most of Java programmer given Callable is new interface introduced in Java 5. My suggestion is to use Callable when you are doing computation inside Thread as call() method returns FutureTask object which can be used to return result. Avoid Runnable if you are coding in Java 5 even if you don't return Keith Yongnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-21930923041071362562012-04-25T06:24:45.195-07:002012-04-25T06:24:45.195-07:00@Gautam and @Anonymous, Thanks for your comment an...@Gautam and @Anonymous, Thanks for your comment and glad to hear that you like difference between Runnable and Thread and this article helps you to decide when to use Runnable interface and when to extend Thread class while creating Thread in Java.Javin @ List vs Set Javahttp://javarevisited.blogspot.com/2012/04/difference-between-list-and-set-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-67281397887083004102012-04-10T19:53:57.967-07:002012-04-10T19:53:57.967-07:00whenever I create Thread, I always face issue whet...whenever I create Thread, I always face issue whether to extend Thread class or implement Runnable interface. I was not aware of difference in extending Thread class and implementing Runnable interface. After reading this article I know much more about Runnable interface and when should I use Runnable interface or Thread class. Can you also provide an example of implementing Runnable and Gautamnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-30905259208635412972012-03-26T02:37:26.717-07:002012-03-26T02:37:26.717-07:00@Rahul, Thanks for your comment. Indeed Runnable i...@Rahul, Thanks for your comment. Indeed Runnable is an interface and not a class.Javin @ race condition in javahttp://javarevisited.blogspot.com/2012/02/what-is-race-condition-in.htmlnoreply@blogger.com