| 66 | } |
| 67 | |
| 68 | public static void main(String[] args) { |
| 69 | class TestThread extends Thread{ |
| 70 | |
| 71 | @Override |
| 72 | public void run() { |
| 73 | try { |
| 74 | String key = ""+getId(); |
| 75 | Watermarks w = new Watermarks("/temp/del/t.xml"); |
| 76 | |
| 77 | String value = null; |
| 78 | |
| 79 | while(!"19".equals(value)){ |
| 80 | value = w.readValue(key); |
| 81 | if (value == null){ |
| 82 | value = "0"; |
| 83 | } |
| 84 | |
| 85 | sleep(1000); |
| 86 | int next = Integer.valueOf(value) + 1; |
| 87 | System.out.println(MessageFormat.format("thread {0} oldvalue {1} newvalue {2}", |
| 88 | key, value, next)); |
| 89 | w.storeValue(key, ""+next); |
| 90 | sleep(1000); |
| 91 | } |
| 92 | |
| 93 | } catch (FileNotFoundException | InterruptedException e) { |
| 94 | e.printStackTrace(); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | for(int i = 0; i < 20; ++i){ |
| 100 | new TestThread().start(); |
| 101 | } |
| 102 | |
| 103 | } |
| 104 | } |