It's not a secret anymore!
The moose likes Java in General and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Threads" Watch "Threads" New topic


Vihanga Rajalingam

Joined: Aug 26, 2012
Posts: 3

class Demo{
public static void main(String args[]){
MyRunnable r=new MyRunnable();
Thread t1=new Thread(r);
for(int i=0;i<100;i++){
System.out.println("main thread "+i);

class MyRunnable implements Runnable{
public void run(){
for(int i=0;i<100;i++){
System.out.println("My thread "+i);

What is the explanation of this program?
Henry Wong

Joined: Sep 28, 2004
Posts: 20538

Vihanga Rajalingam wrote:

What is the explanation of this program?

Looks like a pretty straightforward example. Can you tell us what do you think is going to happen? Have you run it? And what are you confused about?


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Threads
It's not a secret anymore!