/*
 * #%L
 * Bitrepository Core
 * %%
 * Copyright (C) 2010 - 2015 The State and University Library, The Royal Library and The State Archives, Denmark
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */
package org.bitrepository.common;

import java.util.concurrent.ThreadFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Creates thread for executors enforcing the general bit repository guidelines. These include<ul>
 *     <li>Setting thread priority factory configured value.</li>
 *     <li>Setting the thread name to the indicated prefix + a counter indentifying the number of threads created by
 *     this factory.</li>
 *     <li>Adds a error handler logging to the bit repository logger.</li>
 *     <li>Marks the thread as daemon thread.</li>
 *     </ul>
 */
public class DefaultThreadFactory implements ThreadFactory {
    private final String prefix;
    private final int priority;
    private final boolean daemonic;
    private int counter = 0;

    public DefaultThreadFactory(String prefix, int priority) {
        this.prefix = prefix;
        this.priority = priority;
        daemonic = true;
    }

    public DefaultThreadFactory(String prefix, int priority, boolean daemonic) {
        this.prefix = prefix;
        this.priority = priority;
        this.daemonic = daemonic;
    }

    @Override
    public synchronized Thread newThread(Runnable r) {
        Thread newThread = new Thread(r, prefix + "-Thread" +counter);
        newThread.setPriority(priority);
        newThread.setDaemon(daemonic);
        newThread.setUncaughtExceptionHandler((thread, throwable) -> {
            String throwingClass = throwable.getStackTrace()[0].getClassName();
            Logger logger = LoggerFactory.getLogger(throwingClass);
            logger.error("UncaughtExceptionHandler caught Exception:", throwable);
        });
        counter++;
        return newThread;
    }
}

@@ -2247,16 +2247,136 @@
 ler(
-(thread,
+new Thread.UncaughtExceptionHandler() %7B%0A            @Override%0A            public void uncaughtException(Thread thread, Throwable
  thr
@@ -2387,13 +2387,14 @@
 le) 
--%3E %7B%0A
+%7B%0A    
     
@@ -2469,16 +2469,20 @@
 Name();%0A
+    
         
@@ -2553,16 +2553,20 @@
         
+    
 logger.e
@@ -2628,16 +2628,30 @@
 wable);%0A
+            %7D%0A
         

Use Anonymous Class instead of Functional Interface