<commit_before>package com.koverse;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.zookeeper.server.ZooTrace;


public class ApplicationServletContextListener implements
		ServletContextListener {

	private Connector connector;
	private Instance instance;
	
	public void contextDestroyed(ServletContextEvent event) {
		
		try {
			System.out.println("Closing Instance");
			instance.close();
			System.out.println("Instance closed");
		}
		catch (AccumuloException e) {
			e.printStackTrace();
		}
		
		System.out.println("Context Destroyed");

	}

	public void contextInitialized(ServletContextEvent event) {
				 
		instance = new ZooKeeperInstance("kv_vagrant", "vagrant");
		try {
			connector = instance.getConnector("root", "vagrant".getBytes());
		} catch (AccumuloException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (AccumuloSecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println("Context Initialized");

	}
}<commit_msg>added comment regarding the Thread.sleep()'s purpose<commit_after>package com.koverse;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.ZooKeeperInstance;


public class ApplicationServletContextListener implements
		ServletContextListener {

	private Connector connector;
	private Instance instance;
	
	public void contextDestroyed(ServletContextEvent event) {
		
		//try {
			System.out.println("Closing Instance");
			//instance.close();
			System.out.println("Instance closed...waiting");
			
			/*
			 * Currently it appears we need to wait for the ZK threads (particularly the ClientCnxn SendThread)
			 *  to shutdown before letting the container clean up the application/drop loaded classes. If we do 
			 *  not sleep, the container will clean up the application and when the ZK ClientCnxn SendThread finally
			 *  stops, we end up seeing a
			 *  java.lang.NoClassDefFoundError: org/apache/zookeeper/server/ZooTrace
			 *  as the ZK code is trying to use ZooTrace which has already been unloaded by the container. The 
			 *  ZooKeeper.close() method isn't blocking and it doesn't appear there is any way to know when the
			 *  internal threads have actually exited.
			 *  
			 *  This is the same issue a user appears to have with Tomcat
			 *  http://mail-archives.apache.org/mod_mbox/tomcat-users/201306.mbox/%3CBAY174-W2088813852FC18913D5FC8A89B0@phx.gbl%3E
			 *  also cross posted at
			 *  http://mail-archives.apache.org/mod_mbox/zookeeper-user/201306.mbox/%3CBAY174-W21494DF40247669DA7B719A89B0@phx.gbl%3E
			 */
			try {
				Thread.sleep(2000);
			}
			catch (InterruptedException ie) {
				ie.printStackTrace();
			}
		//}
		//catch (AccumuloException e) {
		//	e.printStackTrace();
		//}
		
		System.out.println("Context Destroyed");

	}

	public void contextInitialized(ServletContextEvent event) {
				 
		
		instance = new ZooKeeperInstance("kv_vagrant", "vagrant");
		try {
			connector = instance.getConnector("root", "vagrant".getBytes());
		} catch (AccumuloException e) {
			e.printStackTrace();
		} catch (AccumuloSecurityException e) {
			e.printStackTrace();
		}
		
		System.out.println("Context Initialized");

	}
}
{'fraction_non_alphanumeric': 0.10081173081958628, 'fraction_numerical': 0.01728201099764336, 'mean_word_length': 4.204359673024523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4332601', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1125, 'n_words': 262}