001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 * 012 * $Id$ 013 * 014 */ 015package org.nuxeo.ecm.core.convert.cache; 016 017import java.util.concurrent.TimeUnit; 018 019import org.apache.commons.logging.Log; 020import org.apache.commons.logging.LogFactory; 021import org.nuxeo.ecm.core.convert.service.ConversionServiceImpl; 022 023/** 024 * Task for GC dedicated Thread. 025 * 026 * @author tiry 027 */ 028public class GCTask implements Runnable { 029 030 public boolean GCEnabled = true; 031 032 private static final Log log = LogFactory.getLog(GCTask.class); 033 034 @Override 035 public void run() { 036 log.debug("starting GC thread"); 037 while (GCEnabled) { 038 ConversionCacheGCManager.gcIfNeeded(); 039 try { 040 long gcInterval = ConversionServiceImpl.getGCIntervalInMinutes(); 041 042 if (gcInterval < 0) { 043 // for tests 044 log.debug("GC sleeps for " + -gcInterval); 045 Thread.sleep(-gcInterval); 046 } else { 047 log.debug("GC sleeps for " + gcInterval * 60 * 1000); 048 // GC Interval is stored in minutes 049 Thread.sleep(TimeUnit.MILLISECONDS.convert(gcInterval, TimeUnit.MINUTES)); 050 } 051 } catch (InterruptedException e) { 052 GCEnabled = false; 053 log.info("GCThread bruttaly interupted"); 054 Thread.currentThread().interrupt(); 055 } 056 } 057 } 058 059}