Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 36641 invoked from network); 5 Jan 2009 12:50:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jan 2009 12:50:37 -0000 Received: (qmail 78205 invoked by uid 500); 5 Jan 2009 12:50:37 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 78163 invoked by uid 500); 5 Jan 2009 12:50:36 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 78154 invoked by uid 99); 5 Jan 2009 12:50:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jan 2009 04:50:36 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jan 2009 12:50:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 640BC2388988; Mon, 5 Jan 2009 04:50:13 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r731544 - /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Date: Mon, 05 Jan 2009 12:50:13 -0000 To: sling-commits@incubator.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090105125013.640BC2388988@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Mon Jan 5 04:50:12 2009 New Revision: 731544 URL: http://svn.apache.org/viewvc?rev=731544&view=rev Log: SLING-635: Remove a thread after two clean up cycles by marking it in the first cycle to be removed and remove it in the second cycle - if the thread hasn't been used in the meantime. Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=731544&r1=731543&r2=731544&view=diff ============================================================================== --- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java (original) +++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Mon Jan 5 04:50:12 2009 @@ -283,6 +283,31 @@ } } } + // check for idle threads + synchronized ( this.jobQueues ) { + final Iterator> i = this.jobQueues.entrySet().iterator(); + while ( i.hasNext() ) { + final Map.Entry current = i.next(); + final JobBlockingQueue jbq = current.getValue(); + if ( jbq.size() == 0 ) { + if ( jbq.isMarkedForCleanUp() ) { + // set to finished + jbq.setFinished(true); + // wake up + try { + jbq.put(new EventInfo()); + } catch (InterruptedException e) { + this.ignoreException(e); + } + // remove + i.remove(); + } else { + // mark to be removed during next cycle + jbq.markForCleanUp(); + } + } + } + } } } @@ -481,7 +506,7 @@ */ private void runJobQueue(final String queueName, final JobBlockingQueue jobQueue) { EventInfo info = null; - while ( this.running ) { + while ( this.running && !jobQueue.isFinished() ) { if ( info == null ) { // so let's wait/get the next job from the queue try { @@ -492,7 +517,7 @@ } } - if ( info != null && this.running ) { + if ( info != null && this.running && !jobQueue.isFinished() ) { synchronized ( jobQueue.getLock()) { final EventInfo processInfo = info; info = null; @@ -1394,8 +1419,13 @@ private boolean isWaiting = false; + private boolean markForCleanUp = false; + + private boolean finished = false; + public EventInfo waitForFinish() throws InterruptedException { this.isWaiting = true; + this.markForCleanUp = false; this.lock.wait(); this.isWaiting = false; final EventInfo object = this.eventInfo; @@ -1403,6 +1433,16 @@ return object; } + public void markForCleanUp() { + if ( !this.isWaiting ) { + this.markForCleanUp = true; + } + } + + public boolean isMarkedForCleanUp() { + return !this.isWaiting && this.markForCleanUp; + } + public void notifyFinish(EventInfo i) { this.eventInfo = i; this.lock.notify(); @@ -1415,6 +1455,14 @@ public boolean isWaiting() { return this.isWaiting; } + + public boolean isFinished() { + return finished; + } + + public void setFinished(boolean flag) { + this.finished = flag; + } } private static final class StartedJobInfo {