tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leon Rosenberg <rosenberg.l...@gmail.com>
Subject Re: How to start a daemon without getting the warning?
Date Wed, 27 Oct 2010 21:57:35 GMT
Hello Konstantin,

On Wed, Oct 27, 2010 at 11:53 PM, Konstantin Kolinko
<knst.kolinko@gmail.com> wrote:
> 2010/10/28 Leon Rosenberg <rosenberg.leon@gmail.com>:
>>
>> Well, that would just move the problem from stopping Timer to calling
>> shutdown on  Executor, wouldn't it?
>>
>
> The problem is with the Thread.getContextClassLoader() for your
> thread.  It contains a reference to the webapp classloader, and thus
> does not allow to GC it.

But I can't detect any obvious Thread.getContextClassLoader() calls in
the code below:

public class BuiltInMemoryPoolProducer implements IStatsProducer{
	/**
	 * The id of the producers. Usually its the name of the pool.
	 */
	private String producerId;
	/**
	 * Associated stats.
	 */
	private MemoryPoolStats stats;
	/**
	 * Stats container
	 */
	private List<IStats> statsList;

	/**
	 * The monitored pool.
	 */
	private MemoryPoolMXBean pool;
	/**
	 * Timer instance for this producer type.
	 */
	private static final Timer timer = new Timer("MoskitoMemoryPoolReader", true);
	
	/**
	 * Creates a new producers object for a given pool.
	 * @param aPool
	 */
	public BuiltInMemoryPoolProducer(MemoryPoolMXBean aPool){
		pool = aPool;
		producerId = "MemoryPool-"+pool.getName()+"-"+(pool.getType()==MemoryType.HEAP?
"Heap" : "NonHeap");
		statsList = new CopyOnWriteArrayList<IStats>();
		stats = new MemoryPoolStats(producerId);
		statsList.add(stats);
		
		timer.scheduleAtFixedRate(new TimerTask() {
			@Override
			public void run() {
				readMemory();
			}
		}, 0, 1000L*60);
		readMemory();
	}
	
	@Override
	public String getCategory() {
		return "memory";
	}

	@Override
	public String getProducerId() {
		return producerId;
	}

	@Override
	public List<IStats> getStats() {
		return statsList;
	}

	@Override
	public String getSubsystem() {
		return SUBSYSTEM_BUILTIN;
	}
	
	private void readMemory() {
		MemoryUsage usage = pool.getUsage();
		stats.setCommited(usage.getCommitted());
		stats.setUsed(usage.getUsed());
		stats.setInit(usage.getInit());
		stats.setMax(usage.getMax());
	}
	
	/**
	 * This method is used internally for virtual producers / stats.
	 * @return
	 */
	MemoryPoolStats getMemoryPoolStats(){
		return stats;
	}
}




>
>
> Note, that the webapp classloader cannot be used anymore once the
> application is stopped. Any attempt to load classes through it will
> fail.
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message