%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.threads.JoinTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.jelly.tags.threads; |
|
17 | ||
18 | import org.apache.commons.jelly.XMLOutput; |
|
19 | ||
20 | import java.util.List; |
|
21 | ||
22 | /** |
|
23 | * A thread join waits until a thread or threadGroup is complete. |
|
24 | * |
|
25 | * @author <a href="mailto:jason@jhorman.org">Jason Horman</a> |
|
26 | */ |
|
27 | ||
28 | 48 | public class JoinTag extends UseThreadTag { |
29 | /** how long to wait */ |
|
30 | 24 | private long timeout = -1; |
31 | ||
32 | /** Perform the thread join */ |
|
33 | protected void useThread(Thread thread, XMLOutput output) throws InterruptedException { |
|
34 | 24 | joinThread(thread); |
35 | 24 | } |
36 | ||
37 | /** Join all of the threads in a thread group */ |
|
38 | protected void useThreadGroup(List threadGroup, XMLOutput output) throws InterruptedException { |
|
39 | 0 | for (int i = 0; i < threadGroup.size(); i++) { |
40 | 0 | joinThread((Thread) threadGroup.get(i)); |
41 | } |
|
42 | 0 | } |
43 | ||
44 | /** Join a thread */ |
|
45 | private void joinThread(Thread thread) throws InterruptedException { |
|
46 | 24 | if (timeout > 0) { |
47 | 0 | thread.join(timeout); |
48 | } else { |
|
49 | 24 | thread.join(); |
50 | } |
|
51 | 24 | } |
52 | ||
53 | /** |
|
54 | * How long should the join wait. If <= 0 the join waits until the |
|
55 | * thread is dead. |
|
56 | * @param timeout in millis |
|
57 | */ |
|
58 | public void setTimeout(long timeout) { |
|
59 | 0 | this.timeout = timeout; |
60 | 0 | } |
61 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |