aspose file tools
The moose likes Threads and Synchronization and the fly likes Waiting for something to happen Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Waiting for something to happen" Watch "Waiting for something to happen" New topic
Author

Waiting for something to happen

Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
The code below defines an class that extracts various details from a response from a server. We then subscribe to a message server, on a specified topic, specifiy that the responses should be processed by the an instance of the class we just defined.
The message sending is asynchronous. I want to wait after I have sent the request, till when I get a response (in the future I will also want to add a timeout). I really can't work out how to do this, if any one could throw any light, I'd be very grateful.
thanks, D.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

go here and download a chess program I wrote long ago, its GPLed.
http://www.rigidsoftware.com/Chess/Download/download.html
There is a class called IOProcessor that does exactly what you are looking for. So it shoudl give you good ideas. I have made a few improvements since then which are not there, but they are small and you will likely find them yourself.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
thanks, but you couldn't give me some pointers could you ? That file is 641 lines long and I'm not sure where exactly I should be looking.
thanks, D.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
CL. Thanks again for your reply. I think I've actually found something that will help me.
Will try it out tomorrow !
D.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Look at the run method only. that is what you are worried about. Look at how it uses a state machine, and how it sleeps when there is no work to be done. Look at how when more work comes in to be done, first the threads state isupdated, then the thread is notified.
ignore all the data parsing stuff.
the point was that this thread reads data from a server. it lays dormant when no data is there. when data arrives its brought to life to process it, then it goes back to sleep. that takes at least 2 threads. one monitoring the server for data, and one that is waiting to process that data.
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
CL. BTW. The Latch worked out perfectly for me thanks....but I'll be sure to take a look at your code when i have a free moment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Waiting for something to happen
 
Similar Threads
a total newbie in Sockets
Java mail problem
NX: URLy Bird 1.3.1 Explicit Fatal Exception Handling
Sending dynamic content by email in jsp