• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multithreading -Doubt about sequential flow of run method

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

please correct me if my understanding is not correct

In multithreading nothing is guaranteed ,but the run method will be executed in the order they are written (may not continuously )
Really confused about the following program's output



and my output is

End of method.
Exception in thread "MyThreadThows" Run // How come run is printed after the exception where as I wrote run method to print first "Run" then throws exception?
hi

End of method.
hi

End of method.
hi

End of method.
hi

java.lang.RuntimeException: Problem
at Thread_Exception.run(Thread_Exception.java:8)
at java.lang.Thread.run(Unknown Source)

 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Are you running this code on command prompt or Eclipse (or some other IDE)?

I think those IDE's go out of sync when handling output and error stream. Though I'm not 100% sure about it.

But when I tried to run this code from command prompt, 'Run' is always printed before exception.
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find the answer here.
 
Ags Karan
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running the program in eclipse . So that might be the reason ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic