aspose file tools*
The moose likes Threads and Synchronization and the fly likes help me guys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
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
Ulf Dittmer
Marshal

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


Ping & DNS - my free Android networking tools app
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: 42292
    
  64
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]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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


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

Joined: Jan 10, 2002
Posts: 61437
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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 ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

"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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me guys