Pattern for Thread Pool?

Hi
i want to build a kind of download manager. The application should be able to handle some concurrent threads, each representing a download in progress.
I thought i might be more efficient to reuse a download thread after the download has ended as to create a new thread each time (like the connection object for db queries). Is this right? If yes, i thought to build a thread pool that serves a limited number of threaded download objects as requested (am I on the right way?).
Now, I have to basic problems: (a) is it right, that, if the run() method of a thread has ended, the whole thread gets destroved? if yes, how should i prevent the thread from being destroyed, so i can reuse it later on? Second (b) how would that pool mechnism look like, means, there must be some kind of vector where i put in and take out the threads.
As you see, these are basic "pool" technique questions. So, I thought, maybe there is a design pattern that would give me the basic mechanism, Does anyone know such a pattern?
Thanks for your help
josh

I thought i might be more efficient to reuse a
download thread after the download has ended as to
create a new thread each time (like the connection
object for db queries). Is this right? If yes, iIt may be right, if creating new threads is wasting enough CPU cycles to justify the complication of a thread pool. Maybe for a high-load server it would be more efficient. You'll have to figure that out for your own specific application.
Another good use for thread pools is to avoid putting time-consuming operations in ActionListeners, etc. Instead you can have them pass the task off to a thread pool, keeping the GUI responsive.
Now, I have to basic problems: (a) is it right, that,
if the run() method of a thread has ended, the whole
thread gets destroved? if yes, how should i prevent
the thread from being destroyed, so i can reuse it
later on? Second (b) how would that pool mechnism look
like, means, there must be some kind of vector where i
put in and take out the threads. (a) You are right. Therefore, the worker threads should not exit their run() methods until interrupted. (b) Worker threads could check a job queue (containing Runnables, perhaps) and if there are none, they should wait() on some object. When another thread adds a new job to the queue, it should call notify() on the same object, thus waking up one of the worker threads to perform the task.
I wrote a thread pool once, just as an exercise. You will run into a number of problems and design issues (such as, what should the worker threads do when interrupted, exit immediately or clear the job queue and then exit?) If you have any more questions, ask in this thead.
Krum

Similar Messages

  • Thread pool small example needed

    Hi friends,
    Can you please give a small example program for thread pool to understand?

    >
    Can you please give a small example program for thread pool to understand?>I don't know (whether you would understand an example - simple or otherwise).
    But why don't you help dispel the impression that you are just another lazy student, by making a start on some code, then asking a specific question, when you get stuck?

  • Thread Pool's decreasing application performance

    Hi,
    In my application, I need to make 10,000 threads for network calls at one instant and release the threads after downloading content.
    Content downloading of individual thread consumes less than 1min.
    When I try this using Timer Task and normal Threads, it works perfectly.
    But after introducing ThreadPool (initial :20,000 ; maximum: 50,000) , the response has degraded.
    Is there any limitations or known issues similar to this for thread pool's.
    Thanks!

    rock_win wrote:
    In my application, I need to make 10,000 threads for network calls at one instant and release the threads after downloading content.10000 threads all doing network connects at the same time? You better contact 10000 distinct servers and have tons of network bandwidth.
    You'll hit problems at that level long before the number of threads becomes a problem.
    Content downloading of individual thread consumes less than 1min.
    When I try this using Timer Task and normal Threads, it works perfectly.What are "normal Threads"? How many operations are you running in parallel here?
    But after introducing ThreadPool (initial :20,000 ; maximum: 50,000) , the response has degraded.You want to have 10000 Threads and declare a pool with 20000 initial threads? Why?

  • A good design for a single thread pool manager using java.util.concurrent

    Hi,
    I am developing a client side project which in distinct subparts will execute some tasks in parallel.
    So, just to be logorroic, something like that:
    program\
                \--flow A\
                           \task A1
                           \task A2
                \--flow B\
                            \task B1
                            \task B2
                            \...I would like both flow A and flow B (and all their launched sub tasks) to be executed by the same thread pool, because I want to set a fixed amount of threads that my program can globally run.
    My idea would be something like:
    public class ThreadPoolManager {
        private static ExecutorService executor;
        private static final Object classLock = ThreadPoolManager.class;
         * Returns the single instance of the ExecutorService by means of
         * lazy-initialization
         * @return the single instance of ThreadPoolManager
        public static ExecutorService getExecutorService() {
            synchronized (classLock) {
                if (executor != null) {
                    return executor;
                } else {
                    // TODO: put the dimension of the FixedThreadPool in a property
                    executor = Executors.newFixedThreadPool(50);
                return executor;
         * Private constructor: deny creating a new object
        private ThreadPoolManager() {
    }The tasks I have to execute will be of type Callable, since I expect some results, so you see an ExecutorService interface above.
    The flaws with this design is that I don't prevent the use (for example) of executor.shutdownNow(), which would cause problems.
    The alternative solution I have in mind would be something like having ThreadPoolManager to be a Singleton which implements ExecutorService, implementing all the methods with Delegation to an ExecutorService object created when the ThreadPoolManager object is instantiated for the first time and returned to client:
    public class ThreadPoolManager implements ExecutorService {
        private static ThreadPoolManager pool;
        private static final Object classLock = ThreadPoolManager.class;
        private ExecutorService executor;
         * Returns the single instance of the ThreadPoolManager by means of
         * lazy-initialization
         * @return the single instance of ThreadPoolManager
        public static ExecutorService getThreadPoolManager() {
            synchronized (classLock) {
                if (pool !=null) {
                    return pool;
                } else {
                    // create the real thread pool
                    // TODO: put the dimension of the FixedThreadPool in a property
                    // file
                    pool = new ThreadPoolManager();
                    pool.executor = Executors.newFixedThreadPool(50);
                    // executor = Executors.newCachedThreadPool();
                    return pool;
         * Private constructor: deny creating a new object
        private ThreadPoolManager() {
        /* ======================================== */
        /* implement ExecutorService interface methods via delegation to executor
         * (forbidden method calls, like shutdownNow() , will be "ignored")
          // .....I hope to have expressed all the things, and hope to receive an answer that clarifies my doubts or gives me an hint for an alternative solution or an already made solution.
    ciao
    Alessio

    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.

  • Custom thread pool for Java 8 parallel stream

    It seems that it is not possible to specify thread pool for Java 8 parallel stream. If that's so, the whole functionality is useless in most of the situations. The only situation I can safely use it is a small single threaded application written by one person.
    In all other cases, if I can not specify the thread pool, I have to share the default pool with other parts of the application. If someone submits a task that takes a lot of time, my tasks will get stuck. Is that correct or am I overlooking something?
    Imagine that someone submits slow networking operation to the fork-join pool. It's not a good idea, but it's so tempting that it will be happening. In such case, all CPU intensive tasks executed on parallel streams will wait for the networking task to finish. There is nothing you can do to defend your part of the application against such situations. Is that so?

    You are absolutely correct. That isn't the only problem with using the F/J framework as the parallel engine for bulk operations. Have a look http://coopsoft.com/ar/Calamity2Article.html

  • Thread pool configuration for write-behind cache store operation?

    Hi,
    Does Coherence have a thread pool configuration for the Coherence CacheStore operation?
    Or the CacheStore implementation needs to do that?
    We're using write-behind and want to use multiple threads to speed up the store operation (storeAll()...)
    Thanks in advance for your help.

    user621063 wrote:
    Hi,
    Does Coherence have a thread pool configuration for the Coherence CacheStore operation?
    Or the CacheStore implementation needs to do that?
    We're using write-behind and want to use multiple threads to speed up the store operation (storeAll()...)
    Thanks in advance for your help.Hi,
    read/write-through operations are carried out on the worker thread (so if you configured a thread-pool for the service the same thread-pool will be used for the cache-store operation).
    for write-behind/read-ahead operations, there is a single dedicated thread per cache above whatever thread-pool is configured, except for remove operations which are synchronous and still carried out on the worker thread (see above).
    All above is of course per storage node.
    Best regards,
    Robert

  • Configuration of Thread Pool for CQ's Web Container

    I am trying to detrmine whether there is any specific configuration for tuning the web container thread pool for CQ. The only configuration I observe is OSGi 's Apache Sling Event Thread Pool but tuning this does not directly correlate to the thread pool that is used for serving web requests by the publish instance.
    Any help would be greatly appreciated as I work through tuning our CQ instance.

    Unfortunately, the max thread settings is not exposed in CQ 5.5.However, all the other configurable settings (equivalent for server.xml) can be seen at [1]
    [1] http://localhost:4502/system/console/configMgr/org.apache.felix.http
    This is fixed in CQ 5.6 current release.
    Thanks,
    Varun

  • How can I use the same thread pool implementation for different tasks?

    Dear java programmers,
    I have written a class which submits Callable tasks to a thread pool while illustrating the progress of the overall procedure in a JFrame with a progress bar and text area. I want to use this class for several applications in which the process and consequently the Callable object varies. I simplified my code and looks like this:
            threadPoolSize = 4;
            String[] chainArray = predock.PrepareDockEnvironment();
            int chainArrayLength = chainArray.length;
            String score = "null";
            ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
            CompletionService<String> referee = new ExecutorCompletionService<String>(executor);
            for (int i = 0; i < threadPoolSize - 1; i++) {
                System.out.println("Submiting new thread for chain " + chainArray);
    referee.submit(new Parser(chainArray[i]));
    for (int chainIndex = threadPoolSize; chainIndex < chainArrayLength; chainIndex++) {
    try {
    System.out.println("Submiting new thread for chain " + chainArray[chainIndex]);
    referee.submit(new Parser(chainArray[i]));
    score = referee.poll(10, TimeUnit.MINUTES).get();
    System.out.println("The next score is " + score);
    executor.shutdown();
    int index = chainArrayLength - threadPoolSize;
    score = "null";
    while (!executor.isTerminated()) {
    score = referee.poll(10, TimeUnit.MINUTES).get();
    System.out.println("The next score is " + score);
    index++;
    My question is how can I replace Parser object with something changeable, so that I can set it accordingly whenever I call this method to conduct a different task?
    thanks,
    Tom                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    OK lets's start from the beginning with more details. I have that class called ProgressGUI which opens a small window with 2 buttons ("start" and "stop"), a progress bar and a text area. It also implements a thread pool to conducts the analysis of multiple files.
    My main GUI, which is much bigger that the latter, is in a class named GUI. There are 3 types of operations which implement the thread pool, each one encapsulated in a different class (SMAP, Dock, EP). The user can set the necessary parameters and when clicking on a button, opens the ProgressGUI window which depicts the progress of the respective operation at each time step.
    The code I posted is taken from ProgressGui.class and at the moment, in order to conduct one of the supported operations, I replace "new Parser(chainArray)" with either "new SMAP(chainArray[i])", "new Dock(chainArray[i])", "new EP(chainArray[i])". It would be redundant to have exactly the same thread pool implementation (shown in my first post) written 3 different times, when the only thing that needs to be changed is "new Parser(chainArray[i])".
    What I though at first was defining an abstract method named MainOperation and replace "new Parser(chainArray[i])" with:
    new Callable() {
      public void call() {
        MainOperation();
    });For instance when one wants to use SMAP.class, he would initialize MainOperation as:
    public abstract String MainOperation(){
        return new SMAP(chainArray));
    That's the most reasonable explanation I can give, but apparently an abstract method cannot be called anywhere else in the abstract class (ProgressGUI.class in my case).
    Firstly it should be Callable not Runnable.Can you explain why? You are just running a method and ignoring any result or exception. However, it makes little difference.ExecutorCompletionService takes Future objects as input, that's why it should be Callable and not Runnable. The returned value is a score (String).
    Secondly how can I change that runMyNewMethod() on demand, can I do it by defining it as abstract?How do you want to determine which method to run?The user will click on the appropriate button and the GUI will initialize (perhaps implicitly) the body of the abstract method MainOperation accordingly. Don't worry about that, this is not the point.
    Edited by: tevang2 on Dec 28, 2008 7:18 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Thread pools for execute queues

    We've set up thread pools for several execute queues dedicated to high-load servlets
    in our application. Once in a while, we get into a condition in which none of
    these threads are available and then the threads never become available - we have
    to restart the server.
    I realize that this is a pretty generic description of the problem :-) but I wonder
    if anyone else has encountered this and has an idea what might be causing it ?
    Right now I am guessing that something in our code causes a resource contention
    that eventually deadlocks all the threads. But that is just a guess.

    Ethan,
    "Ethan Allen" <[email protected]> wrote in message
    news:3e0220a1$[email protected]..
    Thanks, Dimitri and Slava !
    I will do this and learn a little emore ...FYI, there is a web site dedicated to weblogic documentation -
    http://e-docs.bea.com/
    Pick your server version, go to "Search", type "thread dump".
    Regards,
    Slava Imeshev
    >
    ethan
    "Slava Imeshev" <[email protected]> wrote:
    Hi Ethan,
    For windows press <Ctrl>+<Break> in the server shell window,
    for *nix send kill -3 {server PID}.
    Regards,
    Slava Imeshev
    "Ethan Allen" <[email protected]> wrote in message
    news:3e020fb4$[email protected]..
    Thanks for your reply, Dimitri.
    We have not looked at thread dumps. How may we do this ?
    Ethan
    "Dimitri I. Rakitine" <[email protected]> wrote:
    Did you try looking at thread dumps when this happens ?
    Ethan Allen <[email protected]> wrote:
    We've set up thread pools for several execute queues dedicated to
    high-load
    servlets
    in our application. Once in a while, we get into a condition in
    which
    none of
    these threads are available and then the threads never become
    available
    - we have
    to restart the server.
    I realize that this is a pretty generic description of the problem:-) but I wonder
    if anyone else has encountered this and has an idea what might be
    causing
    it ?
    Right now I am guessing that something in our code causes a
    resource
    contention
    that eventually deadlocks all the threads. But that is just a
    guess.
    >>>>
    Dimitri

  • [svn] 1605: Bug: BLZ-155 - Deadlock using a thread pool for tomcat connectors

    Revision: 1605
    Author: [email protected]
    Date: 2008-05-07 14:24:53 -0700 (Wed, 07 May 2008)
    Log Message:
    Bug: BLZ-155 - Deadlock using a thread pool for tomcat connectors
    QA: Yes - Jorge verified in the QE lab
    Doc: No
    Ticket Links:
    http://bugs.adobe.com/jira/browse/BLZ-155
    Modified Paths:
    blazeds/branches/3.0.x/modules/core/src/java/flex/messaging/client/EndpointPushNotifier.j ava

    Cross post: http://forum.java.sun.com/thread.jspa?threadID=5215686&tstart=0
    If you must post across forums, just post in the most relevant one and then give the link to that in the other posts.

  • Servlet Thread Pools for iPlanet WS 4.1

    We have iPlanet WS 4.1 SP 5, running on HP UX. Wanted to make sure servlets run fast, so set up servlet thread pool. Initial result was that even the startup servlet could not be loaded, got stack overflow. Reduced number of threads from 60 to 5. Now startup servlet kicked off OK, but a subsequent servlet processing a request bombed with same error. This is obviously some kind of resource issue; how does one allocate enough memory or whatever it needs to handle the thread pool? Do I really even need a thread pool?

    Thanks, and a follow-up question: at that reference, it seemed to imply there is really no need to allocate a user thread pool if running on Unix. Could even slow down the application. Am I likely to be OK with about 300 concurrent users if I don't allocate a thread pool? I was afraid they'd be single-threaded through the front controller servlet if I did not specifically allocate and use a thread pool, but perhaps multiple threads are already built into the container?

  • 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

  • How to correctly use a fixed size thread pool?

    I am quite new to using concurrency in Java, so please forgive if this is a trivial question.
    I would like to make use of something like pool=Executors.newFixedThreadPool(n) to automatically use a fixed number of threads to process pieces of work. I understand that I can asynchronously run some Runnable by one of the threads in the threadpool using pool.execute(someRunnable).
    My problem is this: I have some fixed amount of N datastructures myDS (which are not reentrant or sharable) that get initialized at program start and which are needed by the runnables to do the work. So, what I really would like to do is that I not only reuse N threads but also N of these datastructures to do the work.
    So, lets say I want to have 10 threads, then I would want to create 10 myDS objects once and for all. Each time some work comes in, I want that work to get processed by the next free thread, using the next free datastructure. What I was wondering is if there is something in the library that lets me do the resusing of threads AND datastructures as simply as just reusing a pool of threads. Ideally, each thread would get associated with one datastructure somehow.
    Currently I use an approach where I create 10 Runnable worker objects, each with its own copy of myDS. Those worker objects get stored in an ArrayBlockingQueue of size 10. Each time some work comes in, I get the next Runner from the queue, pass it the piece of work and submit it to the thread pool.
    The tricky part is how to get the worker object back into the Queue: currently I essentially do queue.put(this) at the very end of each Runnable's run method but I am not sure if that is safe or how to do it safely.
    What are the standard patterns and library classes to use for solving this problem correctly?

    Thank you for that feedback!
    There is one issue that worries me though and I obviously do not understand it enough: as I said I hand back the Runnable to the blocking queue at the end of the Runnable.run method using queue.put(this). This is done via a static method from the main class that creates the threads and runnable objects in a main method. Originally I tried to make that method for putting back the Runnable objects serialized but that inevitably always led to a deadlock or hang condition: the method for putting back the runnable was never actually run. So I ended up doing this without serializing the put action in any way and so far it seems to work ... but is this safe?
    To reiterate: I have a static class that creates a thread pool object and a ArrayBlockingQueue queue object of runnable objects. In a loop I use queue.take() to get the next free runnable object, and pass this runnable to pool.execute. Inside the runnable, in method run, i use staticclass.putBack(this) which in turn does queue.put(therunnableigot). Can I trust that this queue.put operation, which can happen from several threads at the same time works without problem without serializing it explicitly? And why would making the staticclass.putBack method serialized cause a hang? I also tried to serialize using the queue object itself instead of the static class, by doing serialize(queue) { queue.put(therunnable) } but that also caused a hang. I have to admit that I do not understand at all why that hang occurred and if I need the serialization here or not.

  • Design Pattern for execution queue

    Anyone know of any good design patterns for using a JMS Queue and MDB's
              as async
              execution queue which maintains execution order by some key
              

    Enforced ordering on redelivery will be supported in the
              next release, but only if the application clamps the pipe-line
              size down to its minimum and the MDB pool size down to one.
              I don't think enforced ordering is supported in the current release.
              We are looking at least partially addressing the general design
              pattern below in the release after next. I don't think I can
              get away with being more specific. (Sorry.) Currently, I
              think something along the line of Larry's solution is the only way to
              accomplish it. Interestingly, the recent thread started
              by "[email protected]" on correlating requests and responses
              seems to be somewhat related.
              Tom, BEA
              Larry Presswood wrote:
              > Well you are both correct however we have something which works
              > however it does involve some threading primitives which generally is not
              > a good idea
              > inside wlas but seems to work.
              >
              >
              > Generally have a singleton on the server which has slots for each key
              > with message
              > numbering for each message and force a wait if message for key is out of
              > order
              > during fifo processing rules. IE do what things you can do in parallel
              > but gate for
              > the last step.
              >
              > I think there is a general remote execution pattern out there.
              >
              > The general problem to solve is this:
              >
              > In a messaging system you want to process messages for each key/session
              > in order however
              > with a large number of sessions its possible to parallel messages for
              > different sessions
              >
              > Otherewise you can either create custom queues or a topic with a
              > selector and then
              > create custom consumers which does not behave as well from a resource
              > perspective
              > as MDB's do.
              >
              >
              >
              >
              >
              >
              >
              > Nick Minutello wrote:
              >
              >>I may be completely wrong - but I think that Larry is referring to the inherant
              >>out-of-order message consumption that you get when using MDB pools to consume
              >>from a Queue.
              >>
              >>In short, the only design pattern here is to deploy the MDB to only one machine
              >>in the cluster - and set the pool size to 1.
              >>
              >>In-order execution is incompatible with the parallel execution that MDB's give
              >>you.
              >>
              >>-Nick
              >>
              >>
              >>
              >>Tom Barnes <[email protected]> wrote:
              >>
              >>
              >>>Hi Larry,
              >>>
              >>>Generally, I think it is best to have a seperate queue per key if the
              >>>
              >>>number of keys is small. This prevents starvation of a particular
              >>>message. For example when handling message-priority, low priority gets
              >>>
              >>>an MDB pool of size 1, high priority gets and MDB pool of size 10.
              >>>
              >>>Note that WebLogic JMS allows a queue to specify a sort-order keys based
              >>>on arbitrary message fields. Note that the in-flight message pipe-line
              >>>
              >>>between server and asynchronous clients is unsorted.
              >>>
              >>>Tom, BEA
              >>>
              >>>Larry Presswood wrote:
              >>>
              >>>
              >>>>Anyone know of any good design patterns for using a JMS Queue and MDB's
              >>>>
              >>>>
              >>>>as async
              >>>>execution queue which maintains execution order by some key
              >>>>
              >>>>
              >>>>
              >>
              >>
              >>
              >
              

  • CVP Opsconsole: Patterns for RNA timeout on outbound SIP calls - Dialed Number (DN) text box does not take any input

    Hi there,
    I'm having problems modifying the 'Dialed Number (DN)' text box under 'Advanced Configuration->Patterns for RNA timeout on outbound SIP calls' of the SIP tab in the Cisco Unified Customer Voice Portal 8.5(1) opsconsole. In a nut shell, I need to change the RNA timeout but some reason when typing into the Dialed Number text box, the input is not taken. The reason I want to change this settings is because my ICM Rona is not working with CVP:
    https://supportforums.cisco.com/thread/2031366
    Thanks in advance for any help.
    Carlos A Trivino
    [email protected]

    Hello Dale,
    CVP doesn't allow you to exceed the RNA more than 60  Seconds. If you want to configure the timer for DN Patterns you should  do it via OPS console, It would update the sip.properties files in  correct way, the above way is incorrect.
    Regards,
    Senthil

Maybe you are looking for