This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on threads  RSS feed

 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Threads4 implements Runnable
{
public static void main (String[] args)
{
Thread t = new Thread(new Threads4());
t.run();
t.run();
t.start();
}
public void run()
{
System.out.println("running");
}
}
o/p is-- runningrunningrunning

Why this is printing 3 times the running.
Can anyone please expalin me this
Source " My own code "
 
Rohit Garg
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its because two times, you have called the run method yourself and once it will be called by the thread you have created

Regards.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!