This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

wait and notify  RSS feed

 
Peter More
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The above code fails sometimes because after waiting in run,it again waits in the loop while(str1 == null). Is there any solution to this problem. Thanks
Peter
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like a lot of errors so its hard to know where to begin. Lets try it in English. What are you trying to do here?
 
Peter More
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to call all the methods invoked in a single thread inside run. I was trying to call getMethod1 in a single thread always. Once getMethod1 is invoked which can be by another thread, I wait until it is executed in the current thread and then return the value. I would have no problem in case getMethod1 had not returned a value, but since it returns a value,
I have made it to wait until the return value is calculated.
Peter
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so run is executed by a single thread, while getMethod1 can be called by any number of threads, but only 1 at a time?
 
Peter More
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have also added a lockmanager to wait and release at the beginning of every method which I have not shown in the code.
Making the thread to wait again until it returns the value is the problem.
If the while(str1 == null) is removed then null is returned and the run method is executed. Is there any solution to this problem. Thanks
Peter
[ January 09, 2004: Message edited by: Peter More ]
[ January 09, 2004: Message edited by: Peter More ]
 
Peter More
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By God's grace I found the solution. The thread was made to wait on another object until the value is calculated. This was required because we wanted to implement this design while invoking methods in JNI. The reason was because the dll is single threaded. So instead of using thread synchronization in c++ and attaching the current thread to jvm, the decision was taken to implement it in java and execute all the methods in a single thread

[ January 12, 2004: Message edited by: Peter More ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!