Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Usage of Thread Pools(Question about how to use the thread pools)
Usage of Thread Pools [message #1734922] Mon, 13 June 2016 18:21 Go to next message
Juergen Messmer is currently offline Juergen MessmerFriend
Messages: 4
Registered: June 2016
Junior Member
Hi,

I am currently creating a binding for reading lines from files continuouslyand parse the new added lines into channels => items.
For every File to be parsed a thing will be created. Every thing needs a worker thread, that reads the file continuously.

I read, that provided thread pools should be used.
As I see from the services.cfg:
# Configuration of scheduled thread pool sizes
org.eclipse.smarthome.threadpool:thingHandler=3
org.eclipse.smarthome.threadpool:discovery=3

# Non-scheduled thread pools can also provide a max size
org.eclipse.smarthome.threadpool:safeCall=3,10

The pool sizes are quite limited.

Is it ok to use the safeCall pool for my purpose like:

...
    private static final String SAFE_CALL_THREADPOOL_NAME = "saveCall";
    protected final ExecutorService executor = ThreadPoolManager.getPool(SAFE_CALL_THREADPOOL_NAME);
    protected Future<?> future = null;

...

    public void startWorker(String fileName, String regEx) {
        logger.debug("Starting Worker thread for " + fileName);
        this.fileToRead = new File(fileName);
        this.regEx = regEx;
        future = executor.submit(this);
    }
...


With this the number of things would be limited to 10.

Is there better way to solve this?

Thanks, Jürgen
Re: Usage of Thread Pools [message #1736098 is a reply to message #1734922] Sat, 25 June 2016 21:30 Go to previous message
Kai Kreuzer is currently offline Kai KreuzerFriend
Messages: 673
Registered: December 2011
Senior Member
Hi Jürgen,

if every Thing needs a dedicated thread, a pool does not seem to be the right choice for you. After all, the idea of a pool is to have many short-lived tasks that share a small number of threads.
In your case, you probably better spawn a dedicated worker thread for each Thing (if this is really required - isn't there maybe a way to use the WatchService from the file system to be informed about file changes, so that you do not have to have so many dedicated threads)?
Previous Topic:Dynamically created channels are not shown
Next Topic:Extension of the DiscoveryResult
Goto Forum:
  


Current Time: Fri Apr 26 15:44:54 GMT 2024

Powered by FUDForum. Page generated in 0.03123 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top