在JAVA中如何实现一个读写锁? 不知道公司情况?www.huawei.com.cn 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class reader extends Thread { public reader(syobj objin){ super(); obj=objin; } private syobj obj=null; public void run(){ for(int i=0;i<100;i++){ System.out.println(obj.getNum()); } }}public class writer extends Thread{ public writer(syobj objin){ super(); obj=objin; } private syobj obj=null; public void run(){ for(int i=0;i<100;i++){ obj.putNum(i); } }}public class syobj { private int num=0; public boolean flag; public synchronized int getNum(){ while(!this.flag){ try{ this.wait(); }catch(Exception e){ System.out.println(e.getMessage()); } } int temp=num; flag=false; this.notify(); return temp; } public synchronized void putNum(int input){ while(this.flag){ try{ this.wait(); }catch(Exception e){ System.out.println(e.getMessage()); } } num=input; flag=true; this.notify(); }}public class testclass { public static void main(String[] args) { syobj obj=new syobj(); writer write=new writer(obj); reader read=new reader(obj); write.start(); read.start(); }} ssh集成关于hibernate问题 请教一个连接池的问题 如何配置log4j让他只显示我log.debug()的内容 jdbc和spring结合,怎么写JDBC与数据库操作的语句? JTA 的问题 救急~~关于Struts的问题!! log4j 设计模式 请问什么时候该使用静态变量呢? javabean可否传递session? 搭建了个SpringMvc的框架,使用Controller跳转时可以跳转到jsp类型的页面,html的确报404. 用j2ee开发erp建议 struts站点问题!在jboss下面,原来站点是myweb.war,现在是webs.war\myweb
public reader(syobj objin){
super();
obj=objin;
}
private syobj obj=null;
public void run(){
for(int i=0;i<100;i++){
System.out.println(obj.getNum());
}
}
}
public class writer extends Thread{
public writer(syobj objin){
super();
obj=objin;
}
private syobj obj=null;
public void run(){
for(int i=0;i<100;i++){
obj.putNum(i);
}
}
}
public class syobj {
private int num=0;
public boolean flag;
public synchronized int getNum(){
while(!this.flag){
try{
this.wait();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
int temp=num;
flag=false;
this.notify();
return temp;
}
public synchronized void putNum(int input){
while(this.flag){
try{
this.wait();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
num=input;
flag=true;
this.notify();
}
}
public class testclass {
public static void main(String[] args) {
syobj obj=new syobj();
writer write=new writer(obj);
reader read=new reader(obj);
write.start();
read.start();
}
}