Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Interacting with a thread from other class  RSS feed

 
s ravi chandran
Ranch Hand
Posts: 547
5
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a problem related to accessing a running thread. I have a thread class which will keep running continuously. now there is another pojo class, which at some point will be calling this class to add or remove items from it.
given below is the code for it.



now this is the code which is called to update the running service



I am starting the service and calling the adder class from a main app.. I think somehow the design is screwed up.. please let me know if this is a proper way or am going in wrong direction.

Thanks
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the question. Why do you think there's a problem? Describe what you think the problem is with evidence and how the problem would act differently if there was no problem.
 
s ravi chandran
Ranch Hand
Posts: 547
5
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I am adding the main class.



As per my understanding, this is what should happen..

first as i start the listing service thread, it should keep printing, "Waiting for stocks".. now when I call stock adder, it should print the add stock statement "adding stocks from"... this is not happening for me.. I even suspect my use of join might be changing the call sequence. most probably the statement waits till listing service completes.. which doesnt happen. I hope i explained the issue here.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying you think you should be seeing output generated as a result of calling StockAdder's AddStock() method? There's a simple reason why you don't see that...
 
s ravi chandran
Ranch Hand
Posts: 547
5
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I think I missed out the method call itself.. will update after checking this.... :-)
 
s ravi chandran
Ranch Hand
Posts: 547
5
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, i added the call, I am not sure if this is updating the same list object in listing service... this is the code with added line..



if i want to have a service continuously running in a console.. is it possible to call any of its methods from another classes from another console? what i was thinking was that, I will have a listing service running continuously, then from another console, I will run main app, which will add, remove or get items from listing service.. I have made stock adder as runnable later on, but the not able to come up with a logical solution to implement it like this..
 
s ravi chandran
Ranch Hand
Posts: 547
5
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
any insight into the problem design issue?

Thanks
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have one console per process (running java application). The problem is very different if you want to communicate between processes was this intended ?
 
s ravi chandran
Ranch Hand
Posts: 547
5
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, if i can start all services from one main class on a console.. that would suffice..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!