Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Thread vs Runnable interface

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    114
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Thread vs Runnable interface

    "The most important difference is - When you extend a thread each of your threads has a unique object associated with it, whereas with Runnable, many threads share the same object instance."

    Can someone explains me how the Runnable interface shares shares same instance more than once?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Thread vs Runnable interface

    You can pass a reference to a class that extends Runnable to more than one Thread object.
    Runnable rnbl = new Runnable();
    new Thread(rnbl);
    new Thread(rnbl);
    new Thread(rnbl);
    The three threads will share the one Runnable.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    114
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Thread vs Runnable interface

    Thanks Norm.

Similar Threads

  1. [SOLVED] Nimbus PLAF: and a double call to repaint() inside a runnable interface
    By chronoz13 in forum AWT / Java Swing
    Replies: 15
    Last Post: August 11th, 2012, 12:59 AM
  2. Replies: 1
    Last Post: August 4th, 2012, 10:02 AM
  3. Exporting Runnable JAR File
    By cr80expert5 in forum Object Oriented Programming
    Replies: 3
    Last Post: January 26th, 2012, 09:35 PM
  4. creating runnable JAR file
    By olimpicco in forum Java IDEs
    Replies: 25
    Last Post: January 11th, 2012, 09:15 AM
  5. Runnable to WebService
    By fran_jo in forum Threads
    Replies: 1
    Last Post: April 12th, 2011, 04:12 PM