Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8355766

Developing startThread API in Runnable interface to improve multithreading learn

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      As a student/new learner/experienced programmer etc., I have to use some common code to create Thread and start it from Runnable functional interface lambda implementation.

      Eg: Runnable test = () -> System.out.println("My Runnable Task");
      Thread t1 = new Thread(test);
      t1.start();

      Could we create default method and its overloaded versions in Runnable interface to move above mentioned last two lines of code to Runnable interface?

      Eg: default Thread startThread() {
              Thread t = new Thread(this);
              t.start();
              return t;
          }

      Then I can create a single/multiple threads using startThread() function on Runnable interface lambda object directly.

      It could be a better option to merge Runnable and Thread APIs into one FunctionalInterface creating simplicity for new developers.

      I am happy to discuss further on it and can contribute to openjdk if required once approved.


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: