• 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
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Output problem

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class ThreadDemo extends Thread{
MyClass ob = new MyClass();
public static void main(String[]args){

new ThreadDemo().start();
new ThreadDemo().start();

}
public void run(){
synchronized(ThreadDemo.class){
ob.fun();
System.out.println(this);//Line 1
}
}
}
class MyClass{
public void fun(){
for(int i = 0 ; i < 4; i++){
try{
Thread.sleep(12);
System.out.println(Thread.currentThread());
}catch(InterruptedException e){
}
}
}
}

Why line 1 not print anything?
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Prasun Howlader:
...
System.out.println(this);//Line 1
System.out.println(Thread.currentThread());
...

Why line 1 not print anything?[/QB]



It does print, it's just that the format for both is exactly the same, you don't know which one is which.

Change line 1 for this: System.out.println("LINE 1" + this);
You should then have 2 output displaying "LINE 1....".


Regards,
Alex
[ January 23, 2008: Message edited by: Alex Belisle Turcot ]
 
please buy this thing and then I get a fat cut of the action:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic