1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.threads;
18
19 import org.apache.commons.jelly.JellyTagException;
20 import org.apache.commons.jelly.XMLOutput;
21
22 /***
23 * This calls mutex.wait() on the mutex passed in via the "mutex" attribute.
24 *
25 * @author <a href="mailto:jason@jhorman.org">Jason Horman</a>
26 */
27
28 public class WaitTag extends UseMutexTag {
29 /*** How long should the wait last. If <=0 it lasts until a notify. */
30 private long timeout = -1;
31
32 /*** Start waiting */
33 public void useMutex(Object mutex, XMLOutput output) throws JellyTagException {
34 try {
35 if (timeout > 0) {
36 mutex.wait(timeout);
37 } else {
38 mutex.wait();
39 }
40 }
41 catch (InterruptedException e) {
42 throw new JellyTagException(e);
43 }
44 }
45
46 /***
47 * Set how long the wait should last. If <= 0 the wait will last
48 * until a notify occurs.
49 * @param timeout in millis
50 */
51 public void setTimeout(long timeout) {
52 this.timeout = timeout;
53 }
54 }