0

I am looking for how to properly start two simple threads in jruby.

In the following with two threads, the message within the first thread does not get printed. I can swap the two threads and the behavior (first thread does not print) persists: so it is not about the contents of the thread (which I stubbed out in any case)

input_before_mysql_phases_t = Thread.new do
  sprint "input_before_mysql_phases completed"
end
mysql_phases_t = Thread.new do
  sprint "mysql_phases completed"
end
sprint "awaiting completion of data fetch phases .."
sleep 5
sprint "data fetch phases completed"

Here is output: notice the message from the first thread is not printed.

    => #<Thread:0x72d006a7 run>
[2013-04-18T12:56:29+00:00] SCHEDULER: mysql_phases completed
irb(main):540:0>     sprint "awaiting completion of data fetch phases .."
[2013-04-18T12:56:29+00:00] SCHEDULER: awaiting completion of data fetch phases ..
=> nil
irb(main):541:0>     sleep 5
=> 5
irb(main):542:0>     sprint "data fetch phases completed"
[2013-04-18T12:56:34+00:00] SCHEDULER: data fetch phases completed
4

1 回答 1

0

功能是什么sprint

这有效:

input_before_mysql_phases_t = Thread.new do
  sleep Random.rand(5) # Random sleep
  sprintf "input_before_mysql_phases completed"
end
mysql_phases_t = Thread.new do
  sleep Random.rand(5) #Random sleep
  sprintf "mysql_phases completed"
end


puts "awaiting completion of data fetch phases .."
# Wait for threads to finish
input_before_mysql_phases_t.join
mysql_phases_t.join
puts "data fetch phases completed"
于 2013-04-18T15:40:32.167 回答