Re: Subclassing Thread?
- From: 7stud -- <dolgun@xxxxxxxxxx>
- Date: Mon, 1 Oct 2007 00:13:09 +0900
Stephen Ware wrote:
Those familiar with threading in Java will know that you can write a
class that is a subclass of Thread, and then put the thread's code into
'public static void run,' which gets executed once thread.start is
called. Can something similar to this be done in Ruby?
The following simulates calling run to start a thread. It stops the
thread as soon as it starts, and then restarts the thread when needed:
class MyThread < Thread
def initialize(x, y)
super(x, y) do |val1, val2|
Thread.stop
puts "In thread..."
puts val1, val2
puts
end
end
end
t = MyThread.new("hello", "world")
puts "main program"
puts
sleep(2)
t.run
t.join
sleep(2)
puts "main program ending..."
--
Posted via http://www.ruby-forum.com/.
.
- Follow-Ups:
- Re: Subclassing Thread?
- From: Kero
- Re: Subclassing Thread?
- References:
- Subclassing Thread?
- From: Stephen Ware
- Subclassing Thread?
- Prev by Date: Re: [QUIZ] Probable Iterations (#141)
- Next by Date: [ANN] Ruby on OpenMoko / Neo1973
- Previous by thread: Re: Subclassing Thread?
- Next by thread: Re: Subclassing Thread?
- Index(es):
Relevant Pages
|