File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes help me guys Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "help me guys" Watch "help me guys" New topic
Author

help me guys

thomas sam
Greenhorn

Joined: Mar 03, 2010
Posts: 5
hi please give me a solution for the below problem


I need d following output :

in AAA thread
in BBB thread
in AAA thread
in BBB thread
in AAA thread
in BBB thread

help me

This message was edited 2 times. Last update was at by Bear Bibeault

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32421
Welcome to JavaRanch.

If you need a certain sequence of events you shouldn't use concurrency - it's up to the JVM how independent threads are scheduled. A combination of wait() and notify() calls can probably achieve what you're asking, but again - if the order of execution is fixed, what's the point of using two threads?

In the future, please UseCodeTags. It's unnecessarily hard to read the code otherwise, making it less likely that people will bother to do so. I have added them for you here. Also please UseAMeaningfulSubjectLine and KeepItDown.

This message was edited 2 times. Last update was at by Ulf Dittmer



Android appsImageJ pluginsJava web charts
thomas sam
Greenhorn

Joined: Mar 03, 2010
Posts: 5
Hi ,
Ya fine. can you send me the proper code for that problem, i already tried with wait & notify, but still i'm struggling with that.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32421
JavaRanch is NotACodeMill. What do you have so far, and where are you stuck making progress?
thomas sam
Greenhorn

Joined: Mar 03, 2010
Posts: 5
In the following code, iam getting null pointer exception





[henry: added code tags]

This message was edited 2 times. Last update was at by Henry Wong

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13411

sun son wrote:In the following code, iam getting null pointer exception


The npe is cause by the fact that your second object is trying to access (line 48) a first reference (line 38) that it never initialized.

Henry

This message was edited 1 time. Last update was at by Henry Wong



Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48842

Please UseAMeaningfulSubjectLine and KeepItDown. I have removed the all uppercase for you.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Michal Bogdal
Greenhorn

Joined: Mar 04, 2010
Posts: 3
Hi All, I have done it in following way:


have a nice day
Michal
thomas sam
Greenhorn

Joined: Mar 03, 2010
Posts: 5
Hi Michel,

Thanks a lot dude:-)
thomas sam
Greenhorn

Joined: Mar 03, 2010
Posts: 5
Hi Michel,


I am having a doubt, by making use of 2 thread alone, can i able 2 synchronize them ?
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48842

"sun son", please check your private messages for an important administrative matter. Again.
Michal Bogdal
Greenhorn

Joined: Mar 04, 2010
Posts: 3
Hi, Thomas. Could you say something more about your doubts? Both threads use synchronized block on the same common object "director", so only one thread can be inside this block at a time. Besides the methods in "Director" class needn't be synchronized, becouse you call them from synchronized block.
Bye
 
 
subject: help me guys
 
developer file tools