1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
<ppdoc>
<copyright>
Copyright (c) 2001 by Addison Wesley Longman. This
material may be distributed only subject to the terms and
conditions set forth in the Open Publication License, v1.0 or
later (the latest version is presently available at
http://www.opencontent.org/openpub/).
</copyright>
<class name="ThreadGroup" super="Object" type="class">
<p/>
<classname>ThreadGroup</classname> provides a means of keeping track of a number of
threads as a group. A <classname>Thread</classname> can belong to only one
<classname>ThreadGroup</classname> at a time; adding a thread to a new group will
remove it from any previous group.
<p/>
Newly created threads belong to the same group as the thread from
which they were created.
<constants>
<tr>
<td><constant>
<constname>Default</constname>
<constval></constval>
<constdesc>Default thread group.</constdesc>
</constant>
</td>
</tr>
</constants>
<p/>
<methods type="class">
<p/>
<method name="new" ref="new">
<callseq>
ThreadGroup.new
<returns><obj>thgrp</obj></returns>
</callseq>
<desc>
<p/>
Returns a newly created <classname>ThreadGroup</classname>. The group is initially
empty.
<p/>
</desc>
</method>
<p/>
</methods>
<p/>
<methods type="instance">
<p/>
<method name="add" ref="add">
<callseq>
<obj>thgrp</obj>.add( <obj>aThread</obj> )
<returns><obj>thgrp</obj></returns>
</callseq>
<desc>
<p/>
Adds the given thread to this group, removing it from any other
group to which it may have previously belonged.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[ puts "Initial group is #{ThreadGroup::Default.list}"
tg = ThreadGroup.new
t1 = Thread.new { sleep 10 }
t2 = Thread.new { sleep 10 }
puts "t1 is #{t1}"
puts "t2 is #{t2}"
tg.add( t1 )
puts "Initial group now #{ThreadGroup::Default.list}"
puts "tg group now #{tg.list}"
]]></fullcode>
puts<nbsp/>"Initial<nbsp/>group<nbsp/>is<nbsp/>#{ThreadGroup::Default.list}"
tg<nbsp/>=<nbsp/>ThreadGroup.new
t1<nbsp/>=<nbsp/>Thread.new<nbsp/>{<nbsp/>sleep<nbsp/>10<nbsp/>}
t2<nbsp/>=<nbsp/>Thread.new<nbsp/>{<nbsp/>sleep<nbsp/>10<nbsp/>}
puts<nbsp/>"t1<nbsp/>is<nbsp/>#{t1}"
puts<nbsp/>"t2<nbsp/>is<nbsp/>#{t2}"
tg.add(<nbsp/>t1<nbsp/>)
puts<nbsp/>"Initial<nbsp/>group<nbsp/>now<nbsp/>#{ThreadGroup::Default.list}"
puts<nbsp/>"tg<nbsp/>group<nbsp/>now<nbsp/>#{tg.list}"
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
Initial<nbsp/>group<nbsp/>is<nbsp/>#<Thread:0x40196528>
t1<nbsp/>is<nbsp/>#<Thread:0x4018d400>
t2<nbsp/>is<nbsp/>#<Thread:0x4018d3c4>
Initial<nbsp/>group<nbsp/>now<nbsp/>#<Thread:0x4018d3c4>#<Thread:0x40196528>
tg<nbsp/>group<nbsp/>now<nbsp/>#<Thread:0x4018d400>
</alltt>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="list" ref="list">
<callseq>
<obj>thgrp</obj>.list
<returns><obj>anArray</obj></returns>
</callseq>
<desc>
<p/>
Returns an array of all existing <classname>Thread</classname> objects that belong
to this group.
<p/>
<codefragment>
<fullcode><![CDATA[ ThreadGroup::Default.list
]]></fullcode><rubycode>
<tr>
<td><tt>ThreadGroup::Default.list</tt></td>
<td>»</td>
<td><tt>[#<Thread:0x40196528<nbsp/>run>]</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
</desc>
</method>
<p/>
</methods>
<p/>
</class>
</ppdoc>
|