OSGI on Websphere ThreadFactory lookup
I'm new to OSGI and working on such project that runs on websphere. I have a simple scheduler, I used java.util.concurrent.ScheduledExecutorService like so:
private ScheduledExecutorService scheduler;
...
scheduler = Executors.newScheduledThreadPool(corePoolSize);
since my application is running inside a container(WebSphere) I though it will be better to let the container manage the threads, so I wanted to use:
scheduler = Executors.newScheduledThreadPool(corePoolSize, threadFactory);
were threadFactory will be in开发者_JAVA百科jected in the blueprint from the container.
I've looked around and could not find an example of how it can be done. So my question is, how can it be done and is it worth the effort at all?
I have found some very useful resource regarding my question,
accurding to this: http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html#spring-4
Other packages, such as quartz and the JDK Timer, start unmanaged threads and should be avoided.
the solution is: http://www.ibm.com/developerworks/websphere/techjournal/0606_johnson/0606_johnson.html#sec5
a sample code is available, basically a custom TheardFactory is implemented using WebSphere WorkManager and than all left to do is initiate ExecutorService with the custom ThreadFactory.
I am not sure where the OSGi tags comes in from this particular case, but there are several links off of this question that you will find useful. I would not use the WorkManager stuff in the article cited in your own answer, as it is very IBM specific and there is a better alternative in the commonj API and for that matter, there is a Timer service as part of the API that may take care of your needs altogether.
If you use Spring, then you can code their integration for task execution and scehduling, which supports the JDK and commonj transparently (at compile time).
精彩评论