Threads: Pooling and groups

Hello there! I need to implement a solution that will use threads, I write down my problem, to be more precisely on the questions.
The scenario:
An extrator, reads from a flat file, and insert into a table.
Another process runs threads to read this table, perform an ETL and then insert in antoher table. I'm considering that the file read process's time is <<< (much smaller) than the ETL, due the transformations involved.
So my first solution was to use thread pooling (Im reading about, and already have some implementations), since I dont want to have more than a few threads running at same time (let's say 5-6).
Ok my first Ideia was to do something like this:
a main class that will run a thread (the text file extractor), this will be done from the pool of threads, so I have n-1 threads left.
This thread would read the lines and at each 10k read, commit the result, and now its the tricky part, warn its parent process (main class) that it already processed 10k registers. The main class would know that and then start a new thread (the ETL thread, reading from 0-10k) now I have n-2 threads left. The process would go on, since the text thread is faster, It would continue warning the main class, that it had processed 10k registers and main class would continue dispatching new threads, untill it reaches a maximum number (controled by the pool). The pool would be responsible to create its own list of waiting threads to run.
My main problem is to make sure that the text thread can warn the main thread. Can someone point me so directions to it? a tutorial, a hint, anything would help

Thread.sleep()
Thread.interrupt()
Well, I'm sorry but I dont think ? I made my self
clear. I need to know how to warn my parent thread not
put the one I'm running in sleep or terminate it.Well. A call to interrupt() does not terminate another thread,
rather, like the name indicates, it interrupts it, but only if
the thread to be interrupted is blocking on a sleep(), join(), or wait() call or is blocking on interruptible I/O (java.nio.channels stuff).
If the thread is not currently blocking, a flag is set.
If there is no need for the parent to sleep() you can just call interrupted() to check the flag at regular intervals.

Similar Messages

  • Cold Fusion in a generic thread pool and enabling JAVA don't mix

    I've got Cold Fusion MX installed on a server running Sun One 6.1. I ran into a problem trying to enable JAVA (for servlet support) which I had previous disabled because I didn't use it.
    Well, when I went to enable JAVA on the server last week, the service wouldn't restart and the error logs gave me no indication of the problem.
    Through a tedious trial-and-error process I've found that having Cold Fusion running under a generic thread pool while trying to have JAVA (the j2ee plugin) running under Sun One simply doesn't work (for whatever reason).
    Once I killed the pool, everything runs fine.
    Does anyone happen to know why this is? I keep CFMX under its own thread pool because there are certain elements to CFMX that aren't wholly stable and can result in CFMX crashing. If it crashes, the process keeps accepting requests, but never processes them. I'd like to keep the native thread pool free to keep accepting non-CFMX requests even when CFMX crashes.
    Thus the separate thread pool for CFMX.
    But now I can't run CFMX in a separate thread pool with JAVA enabled.
    Anyone have any insights into why this is?
    Thanks

    Two things. Firstly, it's better to use     private static final Object classLock = new Object();because that saves you worrying about whether any other code synchronises on it. Secondly, if you do decide to go for the delegation route then java.lang.reflect.Proxy may be a good way forward.

  • On Threads, Pools and other beasts

    I'm seeing some unexpected behaviours in our production system relating to
    (AFAICS) threads and connection pools, and hope you could bring some info
    about them.
    Our system is built over 4 PIII Xeon processors under Linux.
    We do currently have this configuration:
    15 threads for the "default" queue and 10 for an special servlet one, we
    decided to separate threads in two queues in order to assure our users get
    always a thread besides what the rest of the system is "doing".
    Even we do not have a lot of users (about 20 or so) they do generate a lot
    of load as for the bussiness logic inherent to the application.
    For sample, so you can understand what goes with practically any user
    "action", think on this.
    After a user "confirms" some data via a servlet and after executing the data
    validation and bussines rules some messages are sent via JMS to the
    "asynchronous" part of the system (that is running in the same weblogic
    instance). After commiting the user transaction an thus releasing the
    servlet thread, so it can be used by the same or other user, JMS messages
    are delivered to MDBs that must transform information from on-line (servlet)
    processes in different ways so they can be stored onto other systems, i.e.
    into a mainframe, into an XML DB and possibly into another RDBMS. Our
    configuration is that there can be as much as 10 MDB of each type (I mean
    for each kind of "action" of a servlet) running concurrently and as you can
    suppose those processes do take some time to communicate with destination
    systems and perform their work.
    We end at last with a lot of concurrent processes in our system that ends
    some time with the users complaining about system responsiveness.
    After all this explanation I would like to know if 25 threads for
    "background" and on-line processes is too low (as I'm afraid they are). The
    problem is we can't seem to increase the number of threads without being
    very careful with JDBC connection pools.
    Currently we have two connection pools. We do demarcate transactions in the
    clients (servlets, batch processes) we have a "transacted" pool and a "non
    transacted" one.
    We are delegating persistence to the contanier (formally in our case we are
    using TopLink persistence and it uses in it's deployment descriptor both
    types of pools)
    Our configuration is as follows:
    Oracle pool NON Tx 60 connections
    Oracle pool Tx 30 connections
    initially we create 5 connections for each pool with an increment of 5 for
    each one too.
    From the tests I have made I have discovered that setting more threads than
    the minimum amount of pools yields to this exception:
    weblogic.common.ResourceException: No available connections in pool
    myNonTxPool
    at
    weblogic.common.internal.ResourceAllocator.reserve(ResourceAllocator.java:57
    8)
    at
    weblogic.common.internal.ResourceAllocator.reserve(ResourceAllocator.java:40
    5)
    at
    weblogic.common.internal.ResourceAllocator.reserveNoWait(ResourceAllocator.j
    ava:373)
    at
    weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:165
    at
    weblogic.jdbc.common.internal.ConnectionPool.reserveNoWait(ConnectionPool.ja
    va:126)
    at
    weblogic.jdbc.common.internal.RmiDataSource.getPoolConnection(RmiDataSource.
    java:194)
    at
    weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java
    :219)
    the behaviour I would expect is that in case a thread needs a connection and
    there isn't any one available the thread may be blocked and it would receive
    the connecion once one is released, of course as I can see in the stack the
    ConnectionPool.reserveNoWait() method is behaving just the other way.
    The main problem with this is that as you can see we are "forced" to spend
    90 (60+30) connections to the DB (even we will never use more than 25
    (15+10) simultaneously just because we must assure that at least there is
    one "reserved" connection to each thread.
    Our DBA thinks that it can't be possible that we spend such number of
    connections that could be taken by another application(s) (as the DB is
    shared with other apps)
    Currently our DB system is not set as "multithreaded" so each connection
    created against the DB is a process on the system and of course they are a
    really scarce resource.
    My question is. What would be a "fine" number of threads for an application
    like this that is mainly "background-batch processing" but assuring on-line
    users have their threads always available?
    I have just another doubt (maybe this is not the right thread to ask for it
    but...) how does the UserTransaction actually works? I mean, is the
    connection given to the thread (and thus extracted from pool) as soon as the
    thread begin it's work? or is it given in the instant of "commiting" to the
    DB. I know maybe using TopLink changes default Weblogic CMP behaviour but I
    would like to know what the "default" Weblogic behaviour is; and, what
    happens when you don't start a transaction in the client and total execution
    time exceeds 30 seconds? I have seen a rollback due to "exceeding" those 30
    seconds althought I'm sure we do not open any transaction, what kind of
    "transaction" is that? Is just a way of Weblogic to assure a thread is not
    "locked" more than a certain period of time so the system never "stalls"?
    Thanks in advance.
    Regards.
    Ignacio.

    Hi Ignacio,
    See my answer inline.
    "Ignacio G. Dupont" <[email protected]> wrote in message
    news:[email protected]...
    I'm seeing some unexpected behaviors in our production system relating to
    (AFAICS) threads and connection pools, and hope you could bring some info
    about them.
    Our system is built over 4 PIII Xeon processors under Linux.
    We do currently have this configuration:
    15 threads for the "default" queue and 10 for an special servlet one, weThat numbers defines number of concurrent requests services
    associated with that queues can handle. If monitoring CPU utilization
    shows that CPU load is not high, let say less than 90%, - you can increase
    that numbers.
    decided to separate threads in two queues in order to assure our users get
    always a thread besides what the rest of the system is "doing".
    Even we do not have a lot of users (about 20 or so) they do generate a lot
    of load as for the bussiness logic inherent to the application.>
    For sample, so you can understand what goes with practically any user
    "action", think on this.[eaten]
    We end at last with a lot of concurrent processes in our system that ends
    some time with the users complaining about system responsiveness.You will have to run a load test in your QA environment and play with queue
    sizes. In addition, you may want to run a profiler (like JProbe or
    OptimizeIt)
    for maximum load to find if there are bottlenecks in the application.
    After all this explanation I would like to know if 25 threads for
    "background" and on-line processes is too low (as I'm afraid they are).The
    It all depends of the usage pattern. I'd say that for a production
    environment
    with any noticeable load, it's low.
    problem is we can't seem to increase the number of threads without being
    very careful with JDBC connection pools.Yes, you will have to increase size of the pools to match maximum
    number of ongoing transactions. Minimum would be a number of execution
    threads. Actual number should be determined either by load testing or
    by setting it to a guaranteed high level.
    Currently we have two connection pools. We do demarcate transactions inthe
    clients (servlets, batch processes) we have a "transacted" pool and a "non
    transacted" one.
    We are delegating persistence to the contanier (formally in our case weare
    using TopLink persistence and it uses in it's deployment descriptor both
    types of pools)
    Our configuration is as follows:
    Oracle pool NON Tx 60 connections
    Oracle pool Tx 30 connections
    initially we create 5 connections for each pool with an increment of 5 for
    each one too.
    From the tests I have made I have discovered that setting more threadsthan
    the minimum amount of pools yields to this exception:That's quite natural.
    weblogic.common.ResourceException: No available connections in pool
    myNonTxPool[eaten]
    the behaviour I would expect is that in case a thread needs a connectionand
    there isn't any one available the thread may be blocked and it wouldreceive
    That would lock exec threads very quickly. A connection pool is a vital
    resource that is to be available constantly. So weblogic uses fail-fast
    approach so that you can adjust setting to match highest load.
    the connecion once one is released, of course as I can see in the stackthe
    ConnectionPool.reserveNoWait() method is behaving just the other way.>
    The main problem with this is that as you can see we are "forced" to spend
    90 (60+30) connections to the DB (even we will never use more than 25
    (15+10) simultaneously just because we must assure that at least there is
    one "reserved" connection to each thread.That's right.
    Our DBA thinks that it can't be possible that we spend such number of
    connections that could be taken by another application(s) (as the DB is
    shared with other apps)I don't think it's a correct observation. Oracle can be configured to handle
    more connections. I saw weblogic pools configured to handle 200
    connections.
    Currently our DB system is not set as "multithreaded" so each connection
    created against the DB is a process on the system and of course they are a
    scarce resource.Application demand for resources should be satisfied.
    My question is. What would be a "fine" number of threads for anapplication
    like this that is mainly "background-batch processing" but assuringon-line
    users have their threads always available?It should be high enough to satisfy requirement to handle given number
    of concurrent requests processed on given hardware. Normally this
    is determined by load testing and gradual increase of this number
    to the point where you see that hardware (seen as CPU load)
    cannot handle it. Buy the way this point sometimes is unreachable
    as application becomes DB-bound, i.e. bottleneck is shifted to
    the database.
    I have just another doubt (maybe this is not the right thread to ask forit
    but...) how does the UserTransaction actually works? I mean, is the
    connection given to the thread (and thus extracted from pool) as soon asthe
    thread begin it's work? or is it given in the instant of "committing" tothe
    It's given when a connection, assuming it's obtained from TxDatasource,
    is requested.
    DB. I know maybe using TopLink changes default Weblogic CMP behavior but I
    would like to know what the "default" Weblogic behavior is; and, what
    happens when you don't start a transaction in the client and totalexecution
    time exceeds 30 seconds? I have seen a rollback due to "exceeding" those30
    seconds although I'm sure we do not open any transaction, what kind of
    "transaction" is that? Is just a way of Weblogic to assure a thread is notFor instance, stateful session beans are transactional.
    "locked" more than a certain period of time so the system never "stalls"?Basically, no, it's not. There is no way to "unlock" thread after certain
    period.
    So when a queue has finished processing, TX monitor checks the timeout,
    and if there is one, issues a corresponding rollback. So, it's possible
    for thread to run for 10 hours if the timeout is 30 seconds.
    Since 7.0 weblogic is capable of detecting such situations so that
    administrator can be informed about it and required actions can be
    taken [on application side].
    Hope this helps.
    Regards,
    Slava Imeshev

  • Scheduled thread pools and blocking

    Hello,
    I am using a scheduled thread pool created in the following way:
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool();I want to schedule a task on the scheduler, but this task uses a MulticastSocket and can block on:
    byte[] b = new byte[BUFFER_LENGTH];
    DatagramPacket dgram = new DatagramPacket(b, b.length);
    socket.receive(dgram);Say I schedule this code to run at 500 ms. The first run blocks on the receive method. If the block lasts for more that 500ms, what happens when the scheduler allocates another thread at the next 500ms mark? Can I "lose" a thread from the pool permanently? Can I cause a backup of multiple threads blocking every time the scheduler runs the task?
    Thanks!
    -pm

    Well it used to be a plain old Runnable with the receive() inside the run() method, and the runnable was launched inside a Thread. However, I have an infrastructure that adds tasks to a ScheduledExecutorService so that I can run tasks that require a timing mechanism. I also have an ExecutorService for executing tasks at one time. I want to use these concurrency facilities to get this task to always run, not just once, and I thought scheduling would allow that. Would the ExecutorService's submit() method do that? Would it make more sense to have the run() method loop:
    run(){
    byte[] b = new byte[BUFFER_LENGTH];
    DatagramPacket dgram = new DatagramPacket(b, b.length);
    while(true){
    socket.receive(dgram);
    // do something ...
    }and then have ExecutorService simply run execute()?
    Thanks!

  • Basics of Thread Pool and MDB

    Hi,
    I am not able to connects the dots between Self-Tuning Thread Pool Threads ,number of MDB's and Open connection to Queue Manager (Listeners).
    Following is my setting
    1 Self-Tuning Thread Pool : Default i.e 5
    2) Initial Beans in Free Pool: 100
    3) Max Beans in Free Pool : 200
    What i see
    Pool Current Count :- 100 (this is as expected)
    On start up of server 105 MDB's are created (No problem with this ) (Have put static variable incrementing in constructor)
    When Messages are sent to MQ (50-100) the "Beans In Use Count" under Monitoring never shows more then 16
    and finally the "open MQ Count" on MQ Explorer is always 16.
    Questions.
    1) What do i need to change, for increasing the count of "Beans In Use Count" and "open MQ Count" on MQ Explorer to be more than 16?
    2)If the Self-Tuning thread pool is 5, how come 16 beans are executed at once? or its just that 16 are picked from pool and only 5 are executed at given time?
    NOTE:- I am using weblogic app server to connecto IBM MQ with JMS Module, so creating the customer WorkManager and attaching it to my listener (MDB) is not supported by weblogic, it says the mdb is not under webloic thread pool so this settingt will have no effect
    -thnaks

    Hi ,
    You have to create a custom work manager and then you have to associate this customer work manager to the dispatch policy of the MDB to increase the threads.
    Following links would surely help you as TomB has explained the same issue very well, do have a look at them.
    Re: WorkManager Max thread constraints not applied to MDB
    Also you can also go through this links which would help you get more information:
    Topic: Configuring Enterprise Beans in WebLogic Search for "To map an EJB to a workmanager"
    http://middlewaremagic.com/weblogic/?p=5665
    Topic: WebLogic WorkManager with EJB3 And MaxThread Constraint
    http://middlewaremagic.com/weblogic/?p=5507
    Regards,
    Ravish Mody
    http://middlewaremagic.com/weblogic/
    Come, Join Us and Experience The Magic…

  • Thread pool and use database table as queue

    is this possible to use database table as queue rather than using "LinkedBlockingQueue"..and store in memory ? If yes, how do i serialized the task object into table and how to retrieve the task object back when need to be execute by executorservice..?

    cometta wrote:
    is this possible to use database table as queue rather than using "LinkedBlockingQueue"..and store in memory ? If yes, how do i serialized the task object into table and how to retrieve the task object back when need to be execute by executorservice..?From the sound of this I think BDLH is on the right track. I would think in terms of messaging with JMS. There is one potential pitfall you may have to work around. JMS does not guarantee the order in which messages will be extracted from the queue. If the order of messages is important that is a problem you'll have to solve.
    PS.

  • Pool # and thread #

    hello all:
    My understanding about APIs such as Executors#newCachedThreadPool and Executors#newFixedThreadPool is that they have a thread pool and various or fixed number of threads. The source code shows that they internally call ThreadPoolExecutor, whose parameters, corePoolSize or maxPoolSize, IMO, also refer to the number of threads.
    However, when I log the default thread name when using these APIs, I see some format like pool-1-thread-202, pool-3-thread-1, which apprear to me there are multiple pools.
    Any clarifications?
    Thanks,
    John

    Johnny_hunter wrote:
    thanks Jahlborn. I didn't create multile executor instances explicitly - under what circurmstances that the JVM feel needs to create multiple executor instances?for whatever it needs a thread-pool (likely candidates are more significant frameworks like webservers, etc). if you create stack dump of your application, you should be able to see what all the threads are doing. additionally, if you attach a memory profile to your application, you should probably be able to figure out what classes own what thread pools. this should enable you to determine where the other thread pools are getting instantiated.
    Edited by: jtahlborn on Jan 9, 2012 11:23 AM

  • Using AsyncEventHandlers as a RTJ buildin thread pool

    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

    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 IllegalArgumentExceptionand 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

  • Thread pool tuning on J2ee NW04s...

    Hi,
    I have troubles in defining the number of threads in the pool of the server and dispatcher.
    First of all, I know that there are several thread pools depending on the node you are:
      - Server node: System and Application thread pool.
      - Dispatcher: System thread pool.
    I know that application pool is dedicated to client requests that come in and system is for the services, libs and core of the nodes.
    I'd like to know if I set to a server node a certain number of threads for the System and Application pool, what would be the value of the System thread pool of the dispatcher?
    As almost everything is going through the dispatcher before to reach the server node, what would be the number of System threads of the dispatcher if there are two or three server nodes? Should I multiply the number current threads of the dispatcher by the number of server nodes?
    If there are a lot of P4 calls (each call needs System 2 threads, one for the request and one for the response) should I deduce the number of thread of the dispatcher using this formula if there is one server node in the worse case:
    Dispatcher System Threads = Server App Threads + (Server System Threads x 2)
    Thanks in advance,
    Serge.

    Hi Serge,
    One way that you can size the number of threads is by using the monitoring stats in the VA.  VA -> cluster -> dispatcher/server -> services -> monitoring -> Runtime (tab) -> Monitor Tree (tab)
    then Root -> Kernel
    Check the Application Threads Pool and System Threads Pool. 
    As long as you DON'T experience CPU bottlenecking, then you can increase the number of threads, if:
    1) The ActiveThreadsCount is always at the MaximumThreadPoolSize
    2) You are noticing the WaitingTasksCount is always high.
    If you are experiencing CPU bottlenecking then increasing the number of threads is useless.
    Regards
    Anthony

  • JMS Thread Pool Size

    Hi,
              I'm using WLS 6.1. The console has a setting for: JMS Thread Pool Size. I wanted to tune the number of threads used by JMS. I thought JMS asynch consumers would use threads in this pool however that doesn't seem to be the case (they all use the default execute threads and queues). Why is this setting available?
              Note the BEA WebLogic JMS Performance Guide talks about tuning this value from version 6.1 up to 8.1 and states "On the server, incoming JMS related requests execute in the JMS execute queue/thread pool."
              Thanks in advance for any responses,
              Mich

    Disregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.

  • Can I give a certain JSP its own thread pool?

    Hey all,
              The application I'm working on needs to give a certain JSP its own thread pool so that it does not effect the performance of the other pools. I can create the new thread pool and am trying to set the value in web.xml. Here's my entry:
              <servlet>
              <servlet-name>??????</servlet-name>
              <jsp-file>/search/*.jsp</jsp-file>
              <init-param>
                   <param-name>wl-dispatch-policy</param-name>
              <param-value>search</param-value>
              </init-param>
              </servlet>
              Since this is just a JSP can you tell me what I should set the <servlet-name> to?
              Thanks for the help.

    you could also try it here:
    http://web.mac.com/madmax019/0/mx/Favicons%20%26%20URL%20Icons.html
    max

  • Setting Thread pool size

              Hi,
              I want to know if I set a system property "-Dweblogic.ThreadPoolSize", how will the
              WLS get to know that the pool size has been changed, at run time?
              E.g. I pass -Dweblogic.ThreadPoolSize=30 from the command-line. Then if I change
              the pool size to 40 at runtime, is there any event that I can fire for the change
              in property through APIs?
              Thnx in advance.
              Best Regards
              Ali
              

    Disregarding what it is for, in my experience, tuning this setting rarely has much effect. For 6.1, the main thread pool related tunables to look at are the EJB thread pools and EJB max-beans... settings, the "default" thread pool, and the internal thread-pool for stand-alone clients -- all of which are mentioned in the performance guide.

  • Will more number of waiting threads in thread pool degrade performance?

    Hi,
    I use thread pool and set the maximum number of threads to execute. My problem is, the thread pool initiates the number of threads and these threads wait until they get a work. Will this degrade the performance (The threads do I/O operations) ??

    Threads waiting for work will not degrade performance. If your work involves those threads waiting for I/O then that in itself will not degrade performance either (as long as they block and don't poll of course).
    All live threads consume resources however so if you are short on threads or memory then don't create too many of them.
    Pre-starting a large number of threads in a pool can cause a startup delay of course. Generally you should let the pool create threads as needed until it gets to the core pool size.

  • Thread callbacks across thread pools

    Correct me if I'm wrong, but apparently calls such as PostDeferredCallToThread() don't work between thread pools. If I create a thread pool in a main program (operating in the default thread pool) and make threads, I can't make calls to callbacks in the new thread pool. Thread-safe queues and variables, on the other hand, still seem to work.

    See the example in my answer to your other thread.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Combining the fixed and cached thread pools

    Is there a way to 'combine' the behavior of cached and fixed thread pools ? I have a requirement where
    - at startup, I need to execute a fixed number of short-lived tasks at the background
    - after startup, on demand, I need to run one short-lived task at a time
    If I use a fixed thread pool for my startup processing, it creates the fixed number of threads to process the tasks. But subsequently, those many threads are not required since my task submission is going to be one at a time. The remaining (n-1) threads therefore are really sitting idle & useless.
    If I use a cached thread pool, then I cannot constrain the number of threads to run at startup (since it creates one for each task). Though it ends up taking those threads out after they are idle for a fixed period. But I'm worried that it might create many threads and possibly slowing down the startup ?
    Is there a way to create a pool with a fixed number of threads but 'remove' a set of threads when they are idle ?
    TIA

    v_bala wrote:
    Thanks. The SynchronousQueue worked as expected. But I tried a LinkedBlockingQueue with size 1 hoping that would cause the second task submission to cause a new thread creation. It didn't. Instead it queues up the request (maybe the doc in ThreadPoolExecutor says that when it mentions "If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread"). I suppose if I were to try another it would create another thread ? (I was testing with only two tasks - the first one ended up creating a thread for the task and the next got queued since the queue capacity is 1)yes, the TPE will not start adding threads until the queue starts rejecting them. kind of odd in my opinion, but that's how it works.
    Btw, that was an interesting idea to add a task that scale the core pool number down ! Currently it comes back down to just the one thread (my core pool size is one) after the idle timeout but your idea may give me a slightly better response since it will scale down the core pool size quicker....I suppose if there was a task submission before that idle time there maybe a performance hit (but I don't anticipate that in my case )?actually, that won't scale things down any faster. changing the core pool size will not ditch the other threads immediately, they will still stick around until they idle timeout. changing the core pool size allows you to not worry about the queue implementation (the first solution). you can set the initial core pool size to your "max" size on startup, then drop it down for the normal processing, all the while using a linkedblockingqueue of unlimited size.

Maybe you are looking for

  • Odd... songs missing from iTunes, but still on my iPod

    I came across an odd situation, where certain songs (burned and purchased) are listed in the iTunes library, but do not connect to a file on my PowerBook. I don't recall any situation where I would have accidentaly removed the files. For example, I m

  • Safari 5.1 has mysteriously reverted to version 5.0.5!

    I downloaded and installed the Safari 5.1 update as soon as it showed up in Software Update. I really like the new Reading List feature, so there is no chance that I wasn't using Safari 5.1. This morning, I opened Safari to find the Reading List icon

  • Custom field type vs user controls

    hi, I saw one example for creating page layouts. In that they are adding the controls to page layout using custom fields . we can use user controls for same right ? when we need custom field types and when we need user controls.  Thanks,

  • Turning off the apple tv voice

    How do I turn off the Apple TV "voice?"

  • How can i make multiple oracle homes co-exsist on windows

    I have a windows box on which I have just installed oracle 9i and 10g. Whenever I connect through the sqlplus , it defaults to the first one installed which is oracle10g every attempt to connect to the second database which is 9i keeps coming with "O