• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interacting with a thread nullpointer exception

 
s ravi chandran
Ranch Hand
Posts: 469
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This sample application is an improvement over my previous posted question Interacting-thread-class. I have created a StockAdder, StockBroker and StockBidder.

StockAdder and StockBroker are working fine. stock adder will add a stock with random price and stock broker will retrieve it. now i have added a logic where stock broker will initiate call to stock bidders to let highest bidder bid for the stock. if the bid value is successful, the bided stock is added to a list. the design is still incomplete.

now my issue is in running. I am getting null pointer error. I am giving the main classes here.







this is the error I am getting.



I hope I am able to explain the issue clearly.. Please let me know what am i missing in the method call..

Thanks
ravi
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hard to say because the StockBroker class you posted isn't exactly what you used. Specifically, here it doesn't even have a line 48 - which is where the exception states the error occurred. You should always post the exact code you use, not some edited version, at least if you want exception line numbers to be meaningful.

So the exercise for you is: look at line 48 of your StockBroker class and find out which object used in that line is null. That's very easy to do. My guess is that's "maxBidder", because that is not set through all code paths, and you're not checking it for null values.
 
s ravi chandran
Ranch Hand
Posts: 469
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Hard to say because the StockBroker class you posted isn't exactly what you used. Specifically, here it doesn't even have a line 48 - which is where the exception states the error occurred. You should always post the exact code you use, not some edited version, at least if you want exception line numbers to be meaningful.

So the exercise for you is: look at line 48 of your StockBroker class and find out which object used in that line is null. That's very easy to do.


Sorry, I removed few lines from the top which were import statements and package declaration.. adding the full class now..

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had actually edited my previous post - so the answer for you is already in there. Not sure if you saw that.
 
s ravi chandran
Ranch Hand
Posts: 469
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I had actually edited my previous post - so the answer for you is already in there. Not sure if you saw that.

Ok.. I shd have refreshed the page.. Will check the maxbidder object. Thanks!
 
s ravi chandran
Ranch Hand
Posts: 469
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I had actually edited my previous post - so the answer for you is already in there. Not sure if you saw that.


Thanks for the help. I found out the issue. I was generating bidders randomly. Sometimes the random count was coming as 0. hence no bidders were created and max bidder was coming as null.. now one more thing is required here. in place of max bidder logic, I want to use countdown latch or cyclic barrier to let all the bidders bid seperately for the same stock and at the end, decide the successful bid.

is there any possible design to achieve this correctly?
 
s ravi chandran
Ranch Hand
Posts: 469
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am working on the second part of this design. triggering parallel bidding for the stocks from stock broker. the updated classes are given below:





now my problem is with the sequence of events in stock broker. first the bidding is to be executed using executor service. once the bidding has been submitted, i should be getting list of successful bidders. but the problem is the sequence is running parallel... is this is a design problem or am assuming the sequence incorrectly.

this is what I am getting in result



this is how it should always come like:



Thanks
Ravi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!