This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Why "Hello World" printing again and again after Main thread execution ends.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this program, but wondering why "Hello World"is getting printed more than once.

 
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that program should print "Hello World" more than once. Are you sure you have copied the program correctly?
 
manjesh g nair
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it does, can you confirm what you are getting?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

manjesh g nair wrote:I think it does, can you confirm what you are getting?



What does your output look like? Post the exact output as well the details about how you trigger that program for execution.
 
manjesh g nair
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can refer online java editor http://www.compileonline.com/compile_java_online.php

Paste the code and we may get out put somehing like below

Hello World
Thread1 is sleeping
Thread2 is sleeping
Thread3 is sleeping
main is sleeping
Thread4 is sleeping
Thread2 is sleeping
Thread1 is sleeping
Thread3 is sleeping
main is awake
Thread4 is sleeping
Hello World
Thread2 is sleeping
Thread1 is sleeping
main is sleeping
Thread4 is sleeping
Thread3 is sleeping
Thread2 is sleeping
Thread1 is sleeping
main is awake
Thread4 is sleeping
Thread3 is sleeping
Thread2 is sleeping
Thread1 is sleeping
Thread3 is sleeping
Thread4 is sleeping
Hello World
..........................
 
Heena Agarwal
Ranch Hand
Posts: 262
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

manjesh g nair wrote:You can refer online java editor http://www.compileonline.com/compile_java_online.php

Paste the code and we may get out put somehing like below



No.

I am not clicking on that link.

How about you do the pasting yourself? I mean copy and paste the code here.
 
manjesh g nair
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have copied both source code (first post) and output in earlier post, can you please check it...
 
manjesh g nair
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also will be great if you can execute the source code once like any normal Java execution (javac HelloWorld.java) process in any editor,console and verify the output if still you feel something creepy going on . Atleast this way we get confirmation its not just happening in only my machine.
 
author
Posts: 23868
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

manjesh g nair wrote:Also will be great if you can execute the source code once like any normal Java execution (javac HelloWorld.java) process in any editor,console and verify the output if still you feel something creepy going on . Atleast this way we get confirmation its not just happening in only my machine.




Okay. I ran it. And I got "Hello World" exactly once -- right at the beginning.


BTW, I also got "main is sleeping" and "main is awake" exact once too. You seem to be getting lots of those too.

Henry
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it's worth relying on some random website for compiling and triggering the Java program, especially when you are learning the language. It's better to install the JDK locally and try out the programs.
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

manjesh g nair wrote:Also will be great if you can execute the source code once like any normal Java execution (javac HelloWorld.java) process in any editor,console and verify the output if still you feel something creepy going on . Atleast this way we get confirmation its not just happening in only my machine.



For the sake of correctness, javac HelloWorld.java compiles HelloWorld.java file and creates the HelloWorld.class file.
java HelloWorld would execute the class file HelloWorld.class

 
manjesh g nair
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True,i ran in jdk on another machine it was coming properly.So far this compiler was working properly for all samples but looks getting weird with this kind of programs .Not sure what could be the reason anyways I assume "Hello World" should not be coming once so its fine.Unfortunately due to some constraints I cannot install JDK in my machine so was sticking with that online sites but surely is misleading.

I guess JVM over there doesnot behave normally with the interbyte code which was main feature of java portability.Thanks for you suggustions:)
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!