multithreading - Simple jruby threading -
i looking how start 2 simple threads in jruby.
in following 2 threads, message within first thread not printed. can swap 2 threads , behavior (first thread not print) persists: not contents of thread (which stubbed out in case)
input_before_mysql_phases_t = thread.new sprint "input_before_mysql_phases completed" end mysql_phases_t = thread.new sprint "mysql_phases completed" end sprint "awaiting completion of data fetch phases .." sleep 5 sprint "data fetch phases completed"
here output: notice message first thread 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
what sprint
function?
this works:
input_before_mysql_phases_t = thread.new sleep random.rand(5) # random sleep sprintf "input_before_mysql_phases completed" end mysql_phases_t = thread.new sleep random.rand(5) #random sleep sprintf "mysql_phases completed" end puts "awaiting completion of data fetch phases .." # wait threads finish input_before_mysql_phases_t.join mysql_phases_t.join puts "data fetch phases completed"
Comments
Post a Comment