<commit_before>package com.ctrip.platform.dal.dao.helper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

/**
 * Created by lilj on 2018/4/12.
 */
public class DefaultConnectionPhantomReferenceCleaner implements ConnectionPhantomReferenceCleaner {
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultConnectionPhantomReferenceCleaner.class);
    private static AtomicReference<ScheduledExecutorService> defaultConnectionPhantomReferenceCleanerRef = new AtomicReference<>();
    private static final Integer DEFAULT_INTERVAL = 900;
    private static String driverClassName = "com.mysql.jdbc.AbandonedConnectionCleanupThread";
    private static String fieldName = "connectionFinalizerPhantomRefs";
    private static Class<?> nonRegisteringDriver;
    private static Field connectionPhantomReference;
    private static AtomicBoolean started = new AtomicBoolean(false);

    static {
        Runtime.getRuntime().addShutdownHook(new CustomThreadFactory("DefaultConnectionPhantomReferenceCleaner").newThread(new Runnable() {
            public void run() {
                shutdown();
            }
        }));
    }

    @Override
    public void start() throws Exception {
        if (started.getAndSet(true))
            return;
        try {
            nonRegisteringDriver = Class.forName(driverClassName);
            connectionPhantomReference = nonRegisteringDriver.getDeclaredField(fieldName);
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(connectionPhantomReference, connectionPhantomReference.getModifiers() & ~Modifier.FINAL);
            connectionPhantomReference.setAccessible(true);
        } catch (ClassNotFoundException e) {
            LOGGER.error(String.format("Class %s not found", driverClassName), e);
            started.compareAndSet(true,false);
            return;<commit_msg>adapted mysql jdbc driver 5.1.48 version<commit_after>package com.ctrip.platform.dal.dao.helper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

/**
 * Created by lilj on 2018/4/12.
 */
public class DefaultConnectionPhantomReferenceCleaner implements ConnectionPhantomReferenceCleaner {
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultConnectionPhantomReferenceCleaner.class);
    private static AtomicReference<ScheduledExecutorService> defaultConnectionPhantomReferenceCleanerRef = new AtomicReference<>();
    private static final Integer DEFAULT_INTERVAL = 900;
    private static String driverClassName = "com.mysql.jdbc.NonRegisteringDriver";
    private static String ConnectionCleanupClassName = "com.mysql.jdbc.AbandonedConnectionCleanupThread"
    private static String fieldName_5138 = "connectionPhantomRefs";
    private static String fieldName_5148 = "connectionFinalizerPhantomRefs";
    private static Class<?> nonRegisteringDriver;
    private static Class<?> ConnectionCleanupClass;
    private static Field connectionPhantomReference;
    private static AtomicBoolean started = new AtomicBoolean(false);

    static {
        Runtime.getRuntime().addShutdownHook(new CustomThreadFactory("DefaultConnectionPhantomReferenceCleaner").newThread(new Runnable() {
            public void run() {
                shutdown();
            }
        }));
    }

    @Override
    public void start() throws Exception {
        if (started.getAndSet(true))
            return;
        try {
            try {
                ConnectionCleanupClass = Class.forName(ConnectionCleanupClassName);
                connectionPhantomReference = ConnectionCleanupClass.getDeclaredField(fieldName_5148);
            } catch (NoSuchFieldException e1) {
                try {
                    nonRegisteringDriver = Class.forName(driverClassName);
                    connectionPhantomReference = nonRegisteringDriver.getDeclaredField(fieldName_5138);
                } catch (NoSuchFieldException e2) {
                    throw new Exception("Need use 5.1.48 mysql Jdbc driver!", e2);
                }
            }
            Field modifiersField = Field.class.getDeclaredField("modifiers");
            modifiersField.setAccessible(true);
            modifiersField.setInt(connectionPhantomReference, connectionPhantomReference.getModifiers() & ~Modifier.FINAL);
            connectionPhantomReference.setAccessible(true);
        } catch (ClassNotFoundException e) {
            LOGGER.error(String.format("Class %s not found", driverClassName), e);
            started.compareAndSet(true,false);
            return;
{'fraction_non_alphanumeric': 0.08165302455579956, 'fraction_numerical': 0.010181672988620483, 'mean_word_length': 3.546279491833031, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6208277', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1236, 'n_words': 257}