开发者

Scheduling threads without stopping one ?

If I have something like:

require 'xmpp4r' # xmpp4r is a ruby library for xmpp. 
  xmppobject.add_meessage_callback { 开发者_如何学Go|m|
    # do something with |m|
  }
Thread.stop

, the main thread is put to sleep and only then the thread started by the callback continues running.

But if I have something like this:

require 'xmpp4r'

  class Foo::App::Bar < Foo::App::Baz

    def method1
      xmppobject.add_message_callback { |m|
        # do something with |m|
      }
    end

end

, where the main thread belonging to the Foo::App must be running always for the app to work, I can't do a Thread.stop on it, and hence the thread from the callback can't do its job.

This is on jruby, and the suggestions I got on irc: 1) use fibers or 2)condition variables. Someone mentioned fibers don't exactly fit in here. I have just started with threads ( of any sort ), hence would appreciate any suggestions regarding this.


Turned out to be a non-issue. I was misled by an error thrown by the Foo::App.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜