• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Why current code executes only Thread name First in code here

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Ex3 {
   public static void main(String[] args) {
       try{
           //Thread.join example
           Thread t1 = new Thread(() -> {
               for(int i=0; i<300;i++){
                   System.out.println(Thread.currentThread().getName() + " " + i);
               }
           }, "First");
           t1.start();
           
           Thread.currentThread().join();
           
           Thread t2 = new Thread(() -> {
               for(int i=0; i<100;i++){
                   System.out.println(Thread.currentThread().getName() + " " + i);
               }
           }, "Second");
           
           t1.join();
           t2.start();

           for(int i=0; i<100;i++){
               System.out.println(Thread.currentThread().getName() + " main " + i);
           }
       }catch(Exception e){
           System.out.println(e);
       }
   }
}
 
Saloon Keeper
Posts: 7162
165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I'm afraid I don't understand what you're asking. Can you rephrase it? Tell us what you thought would happen, and what happened instead.
 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Consider carefully what this statement does. I suspect you didn't mean to do that.
reply
    Bookmark Topic Watch Topic
  • New Topic