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;是怎么回事
解决方案 »
- JAVA 参数传值问题
- 大家给看看这个算法,不明白是怎么执行的呀,急,一共才十几行代码呀...
- 急问 线程怎么挂起自身啊?
- 请教关于多线程的问题
- java API 里 io.readLine()怎用?
- String s = SendMsg.class.getName(); String m = System.getProperty(s);这是实现了什么功能呀?
- 正则表达式大比拼
- 请教读取相对路径问题,小问题却搞了半天。。急!
- 刚过scjp,89%
- 怎样用java连接sqlserver数据库,不用jdbc-odbc网桥?
- JAVA能拦包吗??就是类似于自动外挂挂机的那种.急急!!!!!!!
- 文件切割机1.3版(开源)-多文件切割,合并批处理!!
-1的时候就是空栈呗