package lesson1; /* * Threads in Java * Option 1 – extending class Thread */ classMyClassextends Thread { @Override publicvoidrun(){ for(int i=0; i<10; i++){ System.out.println(Thread.currentThread().getId()+" Value : "+ i ); }
try{ Thread.sleep(100); }catch(InterruptedException e){ // TODO Auto-generated catch block e.printStackTrace(); } // the super doesn't anything,
// but just for the courtesy and good practice
super.run(); }
}
publicclassDemo{
publicstaticvoidmain(String[] args){ MyClass myClass =new MyClass(); myClass.start();// don't call run! // (if you want a separate thread) MyClass myClass1 =new MyClass(); myClass1.start();
}
}
------------------------------------------------ Searches related to creating first thread java creating a thread in java example creating thread in java using runnable interface how to create a thread in java program create thread in java web application thread in java tutorial thread in java tutorial pdf thread in java tutorial how to create a thread in android How do I create a thread in Java? -
0 comments:
Post a Comment