3 Replies Latest reply: Oct 16, 2008 11:37 AM by 807557 RSS

    using AsyncEventHandlers as a RTJ buildin thread pool

    800408
      Hi David

      1. I would like to use AsyncEventHandler mechanism as a thread pool. Would there be a way in future version to access the AsyncEventHandler's RT Thread pool API ?

      2. I am using the BoundAsyncEventHandler for long duration task (since the BoundAsyncEventHandler is bound to a specific Thread) - Would there be a way in future version to bound a specific RT Thread to this handler ? - for example a RT Thread that was created by my own Thread pool ?

      Thanks
        • 1. Re: using AsyncEventHandlers as a RTJ buildin thread pool
          807557
          Hi Gabi,

          The short is, to both is No. There are no APIs for this and no current proposals to provide anything related to this in the RTSJ.

          But I'd like to understand your requirements a bit better:

          1. How exactly do you want to use the AEH "thread pool"? The VM manages a thread pool for unbound AEH, and the VM may have its own mechanism for specifying some of the characteristics of that pool eg in Sun's Java RTS you can set the initial number of threads.

          2. What characteristic of the BAEH's thread would you want to modify? Most of the visible characteristics come from the BAEH itself; and the BAEH can carry additional state and functionality.

          Cheers,
          David Holmes
          • 2. Re: using AsyncEventHandlers as a RTJ buildin thread pool
            800408
            Hi David

            1.We need our code to access the AEH's "thread pool" and check the pool's availability; increase/decrease the pool size dynamically; check pool size for enough free threads to run any given number of tasks and so on...

            2. I was thinking about adding the BAEH class with the next method:
            void setBoundThread(RTThread t) throws IllegalArgumentException
            and also in the Ctor add the RTThread as a parameter.
            Inside this method, the thread should be check if started and is so should throw an IllegalArgumentException.

            3. Additional question, what do you think about using lock (CountdownLatch) during the AEH's executions ?
            I've seen somewhere that AEH should only be used for short live tasks - is it true ? (in the JavaDoc it says there is no problem doing so but I want to be sure)

            Thanks
            • 3. Re: using AsyncEventHandlers as a RTJ buildin thread pool
              807557
              Gabi wrote:
              1.We need our code to access the AEH's "thread pool" and check the pool's availability; increase/decrease the pool size dynamically; check pool size for enough free threads to run any given number of tasks and so on...
              There are no API's for this. How a VM supports AEH execution is an implementation detail, and while a "pool" is the logical form of implementation the details can vary significantly so there's no real way to define an API to control it without defining what form it must take. For example in Java RTS the pool threads are initially at the highest system priority and then drop down to the priority of the AEH they execute. In a different design you might have a pool of threads per priority level (or set of priority levels) so even the notion of increasing/decreasing the pool size is not necessarily straight-forward. In Java RTS the pool will grow as needed to service outstanding AEH activations. You can control the initial number of threads - and there are two pools: one of heap-using and one for non-heap AEH.
              2. I was thinking about adding the BAEH class with the next method:
              void setBoundThread(RTThread t) throws IllegalArgumentException
              and also in the Ctor add the RTThread as a parameter.
              Inside this method, the thread should be check if started and is so should throw an IllegalArgumentException.
              Sure, but why do you need to do this? What is different about the RTT that you pass in? The thread executing an AEH acquires the characteristics of the AEH.

              An API like this raises some questions such as: when would the thread be started? It also has a problem in that the run() method of the thread has to know how to execute an AEH, which means we'd (the RTSJ expert group) probably have to define a class BoundAEHThread that has a final run() method and you'd then subclass it.
              3. Additional question, what do you think about using lock (CountdownLatch) during the AEH's executions ?
              I've seen somewhere that AEH should only be used for short live tasks - is it true ? (in the JavaDoc it says there is no problem doing so but I want to be sure)
              If an AEH blocks for any length of time and additional AEH are activated then the pool management overhead may increase (unless you already sized it appropriately). But otherwise there's no restriction on what the code in an AEH can do. But note that none of the java.util.concurrent synchronization tools support priority-inversion avoidance, so you need to be careful if using them (ie only use them across threads of the same priority and don't expect FIFO access).

              David Holmes