你看看这个可以不
这个类可以满足你
package net.vlinux.helper;
import java.util.Stack;
/**
*
* @author vlinux
*/
public class SecurityStack<E> {
private Stack<E> stack;
public SecurityStack() {
stack = new Stack<E>();
}
public E peek() {
synchronized(stack) {
return stack.peek();
}
}
public E push(E e) {
synchronized(stack) {
return stack.push(e);
}
}
public E pop() {
synchronized(stack) {
return stack.pop();
}
}
/**
* This is a test.
*/
public static void main(String... args){
SecurityStack<Integer> stack = new SecurityStack<Integer>();
// do something...
}
}