Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: A quota based lock Date: Wed, 10 Aug 2011 18:55:43 +0200 Lines: 35 Message-ID: <9afrgkFri4U1@mid.individual.net> References: <83f81158-8aee-486d-a51b-c0f7dfdbb0da@h25g2000prf.googlegroups.com> <9aasp0F9v2U1@mid.individual.net> <9aeqo2F2e9U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net NjeTmfTT43ljGm8YtUvYVQJ+v11PfqQqcJV4yRFzCJSGUFfnM= Cancel-Lock: sha1:pEX51QDvgc7Z++Fy3baQ3fVRQkM= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6981 Please do not top post. On 10.08.2011 13:40, Robert Stark wrote: > Sorry, i use google groups and i could not find my post until today. > Thank you all! > There is a single resource and i want more sophisticated control over > it, there're different types of jobs( client requests, back-end jobs) > running in my system, every job would hold the resource for 1ms~20ms, > some back-end jobs will run for several hours and they will > continuously acquire this resource, in this case, client requests will > suffered low throughput even starvation, so i come up with this idea, > and i do want to keep it as simple as possible. Client request may > come once a while (10-50 per second), acquire lock 1-2 times and exit. This can never work: if you have jobs that - by design - hold the resource for hours then no amount of lock implementation smartness will prevent starvation without preemption. You cannot have a resource with exclusive access, long access times and responsiveness at the same time. Doing preemption manually will be difficult. It's better to break up long running tasks into smaller sub tasks which need exclusive resource access. Whether that's possible or not depends of course on your business logic (which we still haven't seen). > I want to complete it and test how it goes. Good idea. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/