Robert,

I want to use multi-threading + JRuby to achieve better performance.

My problem has a single input file that contains millions of lines. Each
line is the input of a time-consuming computing and will generate an
output result.

What in my mind is:

1. the main thread prepares N working threads, and put them into sleep
   state.
2. the main thread open the input file and pass the file object to each
   thread[:file]
3. the main thread send a "GO" command to all the working threads
4. each thread works in the below loop:
   4.1 lock the mutex associated with the file object, read a line, and
       then unlcok. if EOF is encountered, exit from the loop.
   4.2 do the very time-consuming computing
   4.3 put the result to thread.current[:result]
   4.4 signal the main thread to pick up the result
   4.5 go to sleep state (waiting for being waken up by the main thread)
5. the main thread works in the below loop:
   5.1 go to sleep state until being waken up by one of the working
       threads.
   5.2 check all the working threads' [:result] and extract them out and
       do some aggregation.
   5.3 for those threads whose result has been picked, send a signal to
       let them proceed with the next line.
6. once all the working threads finish, the main thread output the
   aggregated result.

-- 
Posted via http://www.ruby-forum.com/.