File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Shiraz Khan
Ranch Hand

Joined: Mar 20, 2006
Posts: 51
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 ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41586
    
  54
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.


Ping & DNS - my free Android networking tools app
Shiraz Khan
Ranch Hand

Joined: Mar 20, 2006
Posts: 51
Thanks for pointing out mistake.
But it is still not working
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41586
    
  54
Well, tell us what IS happening. Why do you think that might be?
Mihai Fonoage
Ranch Hand

Joined: Feb 25, 2006
Posts: 39
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

Joined: Mar 20, 2006
Posts: 51
Thanks for the help. It is working now.
My understanding was wrong. I was calling wait on thread rather than on this object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads