Return-Path: X-Original-To: apmail-jackrabbit-users-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DF9AB9A21 for ; Tue, 10 Apr 2012 11:25:21 +0000 (UTC) Received: (qmail 64942 invoked by uid 500); 10 Apr 2012 11:25:21 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 64907 invoked by uid 500); 10 Apr 2012 11:25:21 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 64899 invoked by uid 99); 10 Apr 2012 11:25:21 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2012 11:25:21 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [194.172.26.36] (HELO MX2.aeb.de) (194.172.26.36) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Apr 2012 11:25:14 +0000 X-IronPort-AV: E=Sophos;i="4.75,398,1330902000"; d="scan'208";a="2772923" Received: from unknown (HELO s-hqmx11.pmbelz.de) ([10.237.5.11]) by MX2I.pmbelz.de with ESMTP; 10 Apr 2012 13:25:13 +0200 Received: from S-HQMX9.pmbelz.de ([fe80::bd5e:cd3b:655a:a376]) by s-hqmx11.pmbelz.de ([fe80::e0cc:54bc:3bc4:19e7%10]) with mapi id 14.01.0355.002; Tue, 10 Apr 2012 13:24:52 +0200 From: "Cech. Ulrich" To: "users@jackrabbit.apache.org" Subject: AW: example of running the Garbage Collector? Thread-Topic: example of running the Garbage Collector? Thread-Index: AQHNEO+DhkhaX9Ve4UaUEczo6VLMupaI4JqAgAsUpcA= Date: Tue, 10 Apr 2012 11:24:51 +0000 Message-ID: <25F8304795F51B4396FF549AE1AB0C1B80492B30@S-HQMX9.pmbelz.de> References: In-Reply-To: Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.237.32.233] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org Hi John, I made the following class for running garbage collection in the datastore.= I don't need a transient repository with extra login for this. I only use = the actual RepositoryManagers(s). Bye, Ulrich =20 ************************************************************* import java.util.List; import javax.jcr.RepositoryException; import org.apache.jackrabbit.api.management.DataStoreGarbageCollector; import org.apache.jackrabbit.api.management.RepositoryManager; import edu.umd.cs.findbugs.annotations.SuppressWarnings; /** * The data store never deletes entries except when running data store garb= age * collection. Similar to Java heap garbage collection, data store garbage * collection will first mark all used entries, and later remove unused ite= ms. *

* Data store garbage collection does not delete entries if the identifier = is * still in the Java heap memory. To delete as many unreferenced entries as * possible, call System.gc() a few times before running the data store gar= bage * collection. Please note System.gc() does not guarantee all objects are * garbage collected. *=20 * @author cech *=20 */ public class DataStoreGC extends Thread { /** * The logger for this class. */ private static org.apache.log4j.Logger logger =3D org.apache.log4j.Logger.getLogger(DataStoreGC.class); =20 private List repositoryManagers; /** * Constructs a new DataStoreGC with a list of * RepositoryManager for which the garbage collection * should run. */ public DataStoreGC(List rms) { super(); if (rms =3D=3D null || rms.size() < 1) { throw new IllegalArgumentException( "The list of repository managers is empty."); } setRepositoryManagers(rms); } /** * {@inheritDoc} */ @Override public void run() { while (Thread.currentThread().isInterrupted()) { try { System.out.println("Running DataStoreGC..."); runDataStoreGarbageCollector(); System.out.println("DataStoreGC done."); Thread.sleep(10000); } catch (InterruptedException irex) { // ignore here } catch (RepositoryException repoex) { logger.error("Error while communicating with the repository= .", repoex); try { Thread.sleep(10000); } catch (InterruptedException e) {} } } } /** * Runs the garbage collector for the given RepositoryManagers. If mult= iple * repositories use the same data store, give all RepositoryManagers in= the * parameter list. *=20 * @param rms * @throws RepositoryException */ @SuppressWarnings(value=3D"DM_GC") private int runDataStoreGarbageCollector() throws RepositoryException { int result =3D 0; List rms =3D getRepositoryManagers(); if (rms =3D=3D null || rms.size() < 1) { throw new IllegalArgumentException( "The list of repository managers is empty."); } DataStoreGarbageCollector[] gcs =3D new DataStoreGarbageCollector[rms.size()]; for (int i =3D 0; i < 5; i++) { System.gc(); //ignore FindBugs warning here } for (int i =3D 0; i < rms.size(); ++i) { gcs[i] =3D rms.get(i).createDataStoreGarbageCollector(); } try { /* Mark all records in all repositories */ for (DataStoreGarbageCollector gc : gcs) { gc.mark(); } /* Important to call sweep() on the first GarbageCollector */ result =3D gcs[0].sweep(); } finally { for (DataStoreGarbageCollector gc : gcs) { gc.close(); } } return result; } private List getRepositoryManagers() { return repositoryManagers; } private void setRepositoryManagers(List repositoryMa= nagers) { this.repositoryManagers =3D repositoryManagers; } } *************************************************************