KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > bean > BeanWithNamedLock


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tctest.spring.bean;
5
6 public class BeanWithNamedLock implements IActiveBean, Runnable JavaDoc {
7   private String JavaDoc value = "0";
8
9   private transient boolean started;
10   private transient String JavaDoc localValue;
11   private transient boolean active;
12
13   public String JavaDoc getValue() {
14     return value;
15   }
16
17   public void setValue(String JavaDoc 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 JavaDoc thread = new Thread JavaDoc(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 JavaDoc e) {
48           // ignore
49
}
50       }
51     } finally {
52       this.active = false;
53     }
54   }
55
56 }
57
Popular Tags