01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tctest.spring.bean;
05:
06: public class BeanWithWaitNotify implements IActiveBean, Runnable {
07: private int value = 0;
08: private Object mutex = new Object();
09:
10: private transient boolean started;
11:
12: public String getValue() {
13: synchronized (this ) {
14: return "" + value;
15: }
16: }
17:
18: public void setValue(String value) {
19: synchronized (mutex) {
20: mutex.notifyAll();
21: }
22: }
23:
24: public boolean isActive() {
25: return started;
26: }
27:
28: public void start() {
29: started = true;
30:
31: Thread thread = new Thread(this );
32: thread.start();
33: }
34:
35: public void stop() {
36: started = false;
37: synchronized (mutex) {
38: mutex.notifyAll();
39: }
40: }
41:
42: public void run() {
43: while (started) {
44: synchronized (mutex) {
45: try {
46: mutex.wait();
47: value++;
48: } catch (InterruptedException e) {
49: //
50: }
51: }
52: }
53: }
54:
55: }
|