java - How to make a Thread from its ExecutorService communicate with a Runnable? -
i'm using executorservice
parsing files:
executorservice service = executors.newfixedthreadpool(10);
and later:
service.submit(new fileparser(file));
however tools used parse files require initialization takes quite long. i'd perform initialization once per thread (not once because initialization parameters not thread-safe), , perform parsing in submitted runnable.
i saw threadfactory
can used provide own threads executor, initialize parameters way:
public class mythreadfactory implements threadfactory { public thread newthread(runnable r) { return new mythread(); // initialization part inside constructor } }
however have no idea on how provide new file parse thread... idea?
thanks
you can use threadlocal variable initialization. during each execution, can check if have executed initialization current thread , use storing whatever need.
Comments
Post a Comment