• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Threads

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the code below, I want that thread A runs and prints 5 times, then wait is called to allow thread B run, and when B finishes A resumes back.

output should be like : AAAAABBBBBBBBBBAAAAA



Where am I wrong ?

[ July 10, 2008: Message edited by: Shiraz Khan ]
[ July 10, 2008: Message edited by: Shiraz Khan ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've been around the ranch long enough to know that you should UseCodeTags when posting code of any length. Please go back and edit your post accordingly; it's unnecessarily hard to read as it is.

One thing that leaps out is that you're using "==" to compare strings. Never do that - that's what the equals method is for.
 
Shiraz Khan
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing out mistake.
But it is still not working
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, tell us what IS happening. Why do you think that might be?
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two thinks you should notice:
- you are calling wait on an object different than thread1
- your first condition in the second if statement

Mihai Fonoage
[ July 10, 2008: Message edited by: Mihai Fonoage ]
 
Shiraz Khan
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. It is working now.
My understanding was wrong. I was calling wait on thread rather than on this object.
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic