Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help me guys

 
thomas sam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
thomas sam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch is NotACodeMill. What do you have so far, and where are you stuck making progress?
 
thomas sam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code, iam getting null pointer exception





[henry: added code tags]
 
Henry Wong
author
Marshal
Pie
Posts: 21510
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseAMeaningfulSubjectLine and KeepItDown. I have removed the all uppercase for you.
 
Michal Bogdal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All, I have done it in following way:


have a nice day
Michal
 
thomas sam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michel,

Thanks a lot dude:-)
 
thomas sam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sun son", please check your private messages for an important administrative matter. Again.
 
Michal Bogdal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic