急~~在线等 关于如何锁定java方法 加synchronized限制,进行同步管理 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 方案在类里面声明一个静态属性public class test{ //静态 private static String strTest; public test{ if (strTest == null) strTest = 0; } public void A1() { if ("0".equals(strTest)) { B1(); } } public void B1() { //锁 strTest = 1; ...... //开 strTest = 0; }}大概可以吧 比如Hashtable的get方法定义如下:public synchronized Object get(Object key) { Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { return e.value; } } return null;}加了synchronized限制后,同一时刻,get方法就只允许被一个线程调用 关于项目权限设置的问题~~~~~~~~~~~~~ 有人学过cognos吗? 求教:如何在TOMCAT搭建SSH模板?(Linux debian系统) 急。。急。。大家来看看 因为JAVA,日子过得很慌张——中专生 怎样把从数据库中得到的数据按照某属性值相同并分别放在不同的list里? Spring的AOP 怎样用java操作文件型数据库 你有几个main函数? oracle数据库连接池的问题 这哪错了。。。。??? x509证书问题
在类里面声明一个静态属性
public class test{
//静态
private static String strTest;
public test{
if (strTest == null) strTest = 0;
}
public void A1() {
if ("0".equals(strTest)) {
B1();
}
} public void B1() {
//锁
strTest = 1; ......
//开
strTest = 0;
}}大概可以吧
public synchronized Object get(Object key) {
Entry tab[] = table;
int hash = key.hashCode();
int index = (hash & 0x7FFFFFFF) % tab.length;
for (Entry e = tab[index] ; e != null ; e = e.next) {
if ((e.hash == hash) && e.key.equals(key)) {
return e.value;
}
}
return null;
}加了synchronized限制后,同一时刻,get方法就只允许被一个线程调用