KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > runtime > internal > cflowstack > ThreadStackFactoryImpl


1 /* *******************************************************************
2  * Copyright (c) 2004 IBM Corporation
3  *
4  * All rights reserved.
5  * This program and the accompanying materials are made available
6  * under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * Andy Clement initial implementation
12  * ******************************************************************/

13 package org.aspectj.runtime.internal.cflowstack;
14
15 import java.util.Stack JavaDoc;
16
17 public class ThreadStackFactoryImpl implements ThreadStackFactory {
18
19     private static class ThreadStackImpl extends ThreadLocal JavaDoc implements ThreadStack {
20         public Object JavaDoc initialValue() {
21           return new Stack JavaDoc();
22         }
23         public Stack JavaDoc getThreadStack() {
24             return (Stack JavaDoc)get();
25         }
26     }
27
28     public ThreadStack getNewThreadStack() {
29         return new ThreadStackImpl();
30     }
31     
32     private static class ThreadCounterImpl extends ThreadLocal JavaDoc implements ThreadCounter {
33         
34         public Object JavaDoc initialValue() {
35           return new Counter();
36         }
37         public Counter getThreadCounter() {
38             return (Counter)get();
39         }
40         
41         public void inc() { getThreadCounter().value++; }
42         public void dec() { getThreadCounter().value--; }
43         public boolean isNotZero() { return getThreadCounter().value!= 0; }
44         
45         static class Counter {
46           protected int value = 0;
47         }
48     }
49     
50     public ThreadCounter getNewThreadCounter() {
51         return new ThreadCounterImpl();
52     }
53
54 }
55
Popular Tags