All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.taymindis.ScheduleThreadFactory Maven / Gradle / Ivy

package com.github.taymindis;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class ScheduleThreadFactory implements ThreadFactory
{
   private AtomicInteger counter;
   private String       name;
   private List stats;
 
   public ScheduleThreadFactory(String name) {
      counter = new AtomicInteger();
      this.name = name;
      stats = new ArrayList();
   }

   @Override
   public Thread newThread(Runnable runnable) {
      Thread t = new Thread(runnable, name + "-Thread_" + counter);
      this.counter.incrementAndGet();
      t.setName(String.format("Created thread %d with name %s on %s \n", t.getId(), t.getName(), new Date()));
      stats.add(t);
      return t;
   }

   public String getStats()  {
      StringBuffer buffer = new StringBuffer();
      Iterator it = stats.iterator();
      while (it.hasNext())  {
         buffer.append(it.next().getName());
      }
      return buffer.toString();
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy