resourcecount = 0; resourcemax = max;
resourcecount -= numberof; notifyAll();
while (true) { if ((resourcecount + numberof) <= resourcemax) { resourcecount += numberof; break; } try { wait(); } catch (Exception e) {} }