Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Threads

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for pointing out mistake.
But it is still not working
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
please buy my thing and then I'll have more money:
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!