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 BeanWithNamedLock implements IActiveBean, Runnable {
07: private String value = "0";
08:
09: private transient boolean started;
10: private transient String localValue;
11: private transient boolean active;
12:
13: public String getValue() {
14: return value;
15: }
16:
17: public void setValue(String value) {
18: this .localValue = value;
19: }
20:
21: public boolean isActive() {
22: return active;
23: }
24:
25: public void start() {
26: this .started = true;
27:
28: Thread thread = new Thread(this );
29: thread.start();
30: }
31:
32: public void stop() {
33: this .started = false;
34: }
35:
36: public void run() {
37: try {
38: while (this .started) {
39: this .active = true;
40: if (this .localValue != null) {
41: this .value = this .localValue;
42: this .localValue = null;
43: }
44:
45: try {
46: Thread.sleep(100L);
47: } catch (InterruptedException e) {
48: // ignore
49: }
50: }
51: } finally {
52: this .active = false;
53: }
54: }
55:
56: }
|