Best way to reuse a Runnable

Posted by Gandalf on Stack Overflow See other posts from Stack Overflow or by Gandalf
Published on 2010-05-05T14:46:41Z Indexed on 2010/05/05 15:48 UTC
Read the original article Hit count: 183

I have a class that implements Runnable and am currently using an Executor as my thread pool to run tasks (indexing documents into Lucene).

executor.execute(new LuceneDocIndexer(doc, writer));

My issue is that my Runnable class creates many Lucene Field objects and I would rather reuse them then create new ones every call. What's the best way to reuse these objects (Field objects are not thread safe so I cannot simple make them static) - should I create my own ThreadFactory? I notice that after a while the program starts to degrade drastically and the only thing I can think of is it's GC overhead. I am currently trying to profile the project to be sure this is even an issue - but for now lets just assume it is.

© Stack Overflow or respective owner

Related posts about java

Related posts about concurrency