1 4 package com.tctest.spring.bean; 5 6 public class BeanWithNamedLock implements IActiveBean, Runnable { 7 private String value = "0"; 8 9 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 } 50 } 51 } finally { 52 this.active = false; 53 } 54 } 55 56 } 57 | Popular Tags |