class xxx implements Runnable{
Pool pool=new Pool();
public void run(){
while (true) {
try {
synchronized (pool) {
while (pool.isEmpty()) {
pool.wait();
}
key = (object) pool.remove0;
}
opt(key);
}
catch (Exception e) {
}
} public static void put(object key) {
synchronized (pool) {
pool.add(key);
pool.notifyAll();
}
selector.wakeup();
} opt(object key){
}
}
那位大哥知道,这们的代码怎样用原子锁可以实现
Pool pool=new Pool();
public void run(){
while (true) {
try {
synchronized (pool) {
while (pool.isEmpty()) {
pool.wait();
}
key = (object) pool.remove0;
}
opt(key);
}
catch (Exception e) {
}
} public static void put(object key) {
synchronized (pool) {
pool.add(key);
pool.notifyAll();
}
selector.wakeup();
} opt(object key){
}
}
那位大哥知道,这们的代码怎样用原子锁可以实现
只知道对象锁,类锁
没听过原子锁
不太清楚
希望高手来解释下