We need to name our thread pools, specially in Carbon. There may be some we
cannot name in Tomcat, but what we can, we should. This will save lot of
time when we have to debug thread related issues. (e.g. Thread leak, with
names it is very easy to detect which one is leaking).

I will create a redmine.

You can name threads as follows.

1) You can pass your own ThreadFactory to ScheduledThreadPoolExecutor. Your
ThreadFactory will create thread and can give it any name you want. Your
ThreadFactory can also reuseExecutors.defaultThreadFactory(), and only
change the name before returning the thread.

e.g. following will do

    public class NamedThreadFactory implements ThreadFactory{

        final ThreadFactory factory = Executors.defaultThreadFactory();

        AtomicInteger count = new AtomicInteger();

        @Override

        public Thread newThread(Runnable r) {

            Thread thread = factory.newThread(r);

            thread.setName("MyThreadName-"+count.incrementAndGet());

            return thread;

        }

    }

2) If you have Guvava, then you can use ThreadFactoryBuilder

See
http://stackoverflow.com/questions/5740478/how-to-name-the-threads-of-a-thread-pool-in-java


============================
Srinath Perera, Ph.D.
  Director, Research, WSO2 Inc.
  Visiting Faculty, University of Moratuwa
  Member, Apache Software Foundation
  Research Scientist, Lanka Software Foundation
  Blog: http://srinathsview.blogspot.com/
  Photos: http://www.flickr.com/photos/hemapani/
   Phone: 0772360902
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to