package sync;
import java.rmi.*;
import java.rmi.server.*;public class StackImpl extends UnicastRemoteObject implements Stack{
private String name;
private String[] buffer=new String[100];
int point=-1; public StackImpl(String name)throws RemoteException{this.name=name;}
public String getName()throws RemoteException{return name;} public synchronized int getPoint()throws RemoteException{return point;}
public synchronized String pop() throws RemoteException{
this.notifyAll(); while(point==-1){
System.out.println(Thread.currentThread().getName()+": wait");
try{
this.wait();
}catch(InterruptedException e){throw new RuntimeException(e);}
} String goods = buffer[point];
buffer[point]=null;
Thread.yield();
point--;
return goods;
}
public synchronized void push(String goods) throws RemoteException{
this.notifyAll(); while(point==buffer.length-1){
System.out.println(Thread.currentThread().getName()+": wait");
try{
this.wait();
}catch(InterruptedException e){throw new RuntimeException(e);}
}
point++;
Thread.yield();
buffer[point]=goods;
}
}
point=-1;是怎么回事
import java.rmi.*;
import java.rmi.server.*;public class StackImpl extends UnicastRemoteObject implements Stack{
private String name;
private String[] buffer=new String[100];
int point=-1; public StackImpl(String name)throws RemoteException{this.name=name;}
public String getName()throws RemoteException{return name;} public synchronized int getPoint()throws RemoteException{return point;}
public synchronized String pop() throws RemoteException{
this.notifyAll(); while(point==-1){
System.out.println(Thread.currentThread().getName()+": wait");
try{
this.wait();
}catch(InterruptedException e){throw new RuntimeException(e);}
} String goods = buffer[point];
buffer[point]=null;
Thread.yield();
point--;
return goods;
}
public synchronized void push(String goods) throws RemoteException{
this.notifyAll(); while(point==buffer.length-1){
System.out.println(Thread.currentThread().getName()+": wait");
try{
this.wait();
}catch(InterruptedException e){throw new RuntimeException(e);}
}
point++;
Thread.yield();
buffer[point]=goods;
}
}
point=-1;是怎么回事
-1的时候就是空栈呗