Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads

 
Mona Gadkari
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see this code

here the o/p is expected to be 0 followed 5000or more
but i get only 0 --- why

[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ September 17, 2003: Message edited by: Jessica Sant ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on your operating system (coughWindowscough) output from System.out.print() called right before a program exits may not appear on the console. Either use println() for the second call, or call System.out.flush() after the second print(). Otherwise, your code should work as expected.
 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I complied and ran this code but replaced the line
wait(5000) with
wait()
The program didn't stop executing. My question is : Is notify/notifyAll the only way for the thread to stop waiting?
Thanks,
Lalitha
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Lalitha,
Only other method I can think of is interrup()
 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Barkat...
Could you please refer to some resources for threads. I don't feel very comfortable with them.
Thank you,
Lalitha
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start with thread tutorial at sun site. Follow that up with any books that you are reading. K & B is good but very limited for threads. I also read Ivor Horton's Begining Java 2 and some other books. Refer to JSL and API as much as possible.
Biggest help is practice.
Barkat
 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ....
Lalitha
 
Lalitha Chandran
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ....
Lalitha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic