Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

help me guys

 
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
 
Rancher
Posts: 43011
76
  • 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: 43011
76
  • 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]
 
author
Posts: 23867
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
Marshal
Posts: 67356
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseAMeaningfulSubjectLine and KeepItDown. I have removed the all uppercase for you.
 
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
Marshal
Posts: 67356
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
 
The moustache of a titan! The ad of a flea:
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!