If you're doing this in Java, use the java.util.concurrent package and
its Executor and Future framework, instead of using Thread.start/join,
synchronized etc. directly.

Get the book "Concurrent Programming in Java: Design Principles and
Patterns"  (ISBN 0-201-31009-0) written by the master himself (Doug
Lea; see http://gee.cs.oswego.edu/dl/cpj/ )

 - Godmar

On Feb 18, 2008 2:19 PM, Durbin, Michael R <[EMAIL PROTECTED]> wrote:
> This can be done in Java, but like everything in Java the solution is kind of 
> lengthy and perhaps requires several classes.
>
> I've attached a simple skeleton program that spawns threads to search but 
> then processes only those results returned in the first 10 seconds.  The code 
> for performing the searches is obviously missing as is the consolidation 
> code, but the concurrency issue is addressed.  In this example the search 
> threads aren't killed, but instead left running to finish naturally though 
> their results would be ignored if they weren't done in 10 seconds.  It might 
> be better to kill them depending on the circumstances.
>
> -Mike
>
> -----Original Message-----
> From: Code for Libraries [mailto:[EMAIL PROTECTED] On Behalf Of Eric Lease 
> Morgan
> Sent: Monday, February 18, 2008 1:43 PM
> To: CODE4LIB@LISTSERV.ND.EDU
> Subject: [CODE4LIB] many processes, one resultCode for Libraries [EMAIL 
> PROTECTED]
>
> How do I write a computer program that spawns many processes but
> returns one result?
>
> I suppose the classic example of my query is the federated search. Get
> user input. Send it to many remote indexes. Wait. Combine results.
> Return. In this scenario when one of the remote indexes is slow things
> grind to a halt.
>
> I have a more modern example. Suppose I want to take advantage of many
> Web Services. One might be spell checker. Another might be a
> thesaurus. Another might be an index. Another might be a user lookup
> function. Given this environment, where each Web Service will return
> different sets of streams, how do I query each of them simultaneously
> and then aggregate the result? I don't want to so this sequentially. I
> want to fork them all at once and wait for their return before a
> specific time out. In Perl I can use the system command to fork a
> process, but I must wait for it to return. There is another Perl
> command allowing me to fork a process and keep going but I don't
> remember what it is. Neither one of these solutions seem feasible. Is
> the idea of threading in Java suppose to be able to address this
> problem?
>
> --
> Eric Lease Morgan
> University Libraries of Notre Dame
>
> (574) 631-8604
>

Reply via email to