Thread pool Question

Hi,
Can any one please guide me How do I create a thread pool?
Regards,
Rajesh Kannan. N

1) Dig large hole
2) Fill with water.
3) Invite thread friends over on hot summer days

Similar Messages

  • Thread pool rejecting threads when I don't think it should, ideas?

    Hi,
    I have a server application in which I only want a specific number of simultaneous requests. If the server gets more then this number it is suppose to close the connection (sends an HTTP 503 error to the client). To do this I used a fix thread pool. When I start the server and submit the max number of requests I get the expected behavior. However if I resubmit the request (within a small period of time, e.g. 1-15 seconds after the first one) I get very odd behavior in that some of the requests are rejected. For example if I set the max to 100 the first set of requests will work fine (100 requests, 100 responses). I then submit again and a small number will be rejected (I've seen it range from 1 to 15 rejected)....
    I made a small app which kind of duplicates this behavior (see below). Basically when I see is that the first time submitting requests works fine but the second time I get a rejected one. As best as I can tell none should be rejected....
    Here is the code, I welcome your thoughts or if you see something I am doing wrong here...
    <pre>
    import java.util.concurrent.*;
    import java.util.concurrent.atomic.AtomicInteger;
    public class ThreadPoolTest {
         static AtomicInteger count = new AtomicInteger();
         public static class threaded implements Runnable {
              @Override
              public void run() {
                   System.out.println("In thread: " + Thread.currentThread().getId());
                   try {
                        Thread.sleep(500);
                   } catch (InterruptedException e) {
                        System.out.println("Thread: " + Thread.currentThread().getId()
                                  + " interuptted");
                   System.out.println("Exiting run: " + Thread.currentThread().getId());
         private static int maxThreads = 3;
         private ThreadPoolExecutor pool;
         public ThreadPoolTest() {
              super();
              pool = new java.util.concurrent.ThreadPoolExecutor(
                        1, maxThreads - 1, 60L, TimeUnit.SECONDS,
                        new ArrayBlockingQueue<Runnable>(1));
         public static void main(String[] args) throws InterruptedException {
              ThreadPoolTest object = new ThreadPoolTest();
              object.doThreads();
              Thread.sleep(3000);
              object.doThreads();
              object.pool.shutdown();
              try {
                   object.pool.awaitTermination(60, TimeUnit.SECONDS);
              } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         private void doThreads() {
              int submitted = 0, rejected = 0;
              int counter = count.getAndIncrement();
              for (int x = 0; x < maxThreads ; x++) {
                   try {
                        System.out.println("Run #: " + counter + " submitting " + x);
                        pool.execute(new threaded());
                        submitted++;
                   catch (RejectedExecutionException re) {
                        System.err.println("\tRun #: " + counter + ", submission " + x
                                  + " was rejected");
                        System.err.println("\tQueue active: " + pool.getActiveCount());
                        System.err.println("\tQueue size: " + pool.getPoolSize());
                        rejected++;
              System.out.println("\n\n\tRun #: " + counter);
              System.out.println("\tSubmitted: " + (submitted + rejected));
              System.out.println("\tAccepted: " + submitted);
              System.out.println("\tRejected: " + rejected + "\n\n");
    </pre>

    First thank you for taking the time to reply, I do appreciate it.
    jtahlborn - The code provided here is a contrived example trying to emulate the bigger app as best as I could. The actual program doesn't have any sleeps, the sleep in the secondary thread is to simulate the program doing some work & replying to a request. The sleep in the primary thread is to simulate a small delay between 'requests' to the pool. I can make this 1 second and up to (at least) 5 seconds with the same results. Additionally I can take out the sleep in the secondary thread and still see the a rejection.
    EJP - Yes I am aware of the TCP/IP queue, however; I don't see that as relevant to my question. The idea is not to prevent the connection but to respond to the client saying we can't process the request (send an "HTTP 503" error). So basically if we have, say, 100 threads running then the 101st, connection will get a 503 error and the connection will be closed.
    Also my test platform - Windows 7 64bit running Java 1.6.0_24-b07 (32bit) on an Intel core i7.
    It occurred to me that I did not show the output of the test program. As the output shows below, the first set of requests are all processed properly. The second set of requests is not. The pool should have 2 threads and 1 slot in the queue, so by the time the second "request" is made at least 2 of the requests from the first call should be done processing, so I could possibly understand run 1, submit #2 failing but not submit 1.
    <pre>
    Run #: 0 submitting 0
    Run #: 0 submitting 1
    Run #: 0 submitting 2
    In thread: 8
    In thread: 9
    Exiting run: 8
    Exiting run: 9
         Run #: 0
         Submitted: 3
         Accepted: 3
         Rejected: 0
    In thread: 8
    Exiting run: 8
    Run #: 1 submitting 0
    In thread: 9
    Run #: 1 submitting 1
         Run #: 1, submission 1 was rejected
         Queue active: 1
         Queue size: 2
    Run #: 1 submitting 2
         Run #: 1
         Submitted: 3
         Accepted: 2
         Rejected: 1
    In thread: 8
    Exiting run: 9
    Exiting run: 8
    </pre>

  • 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

  • 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 design

    I have one service that processes messages, now I want it to run it in multi threads so it can execute faster. Now my question is how can I make thread pool- what is best design. Since I dont want to create n number of thereads to process n number of messages, I should create thread pool with predefined number of threads.
    So my main program will do something like this
    1)Check thread pool - if available
    2)If available create tak and execute
    3)If not wait (how to wait???)
    4)Once thread has done it should be available for next processing if requred.
    Thanks in advance.

    I am not using put, I am not directly using array queue, what I understand is like its for its internal use. Here is what I am trying with,
    Thread pool  class
    import java.util.concurrent.BlockingQueue;
    import java.util.concurrent.ThreadPoolExecutor;
    import java.util.concurrent.TimeUnit;
    public class MyThreadPool extends ThreadPoolExecutor {
         public MyThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime,
                   TimeUnit unit, BlockingQueue<Runnable> queue) {
              super(corePoolSize, maximumPoolSize, keepAliveTime, unit, queue);
    Thread- Runnable object
    public class MyThread implements Runnable{
         public void run() {
              System.out.println("This is MyThread running...");
              try {
                   Thread.currentThread().sleep(1*5*1000);
                   System.out.println("Complted...");
              } catch (InterruptedException e) {
                   e.printStackTrace();
    Main program
    public class MyClient {
         public static void main(String[] args) {
              ArrayBlockingQueue queue = new ArrayBlockingQueue(5, false);
              MyThreadPool myThreadPool = new MyThreadPool(5, 5, 1, TimeUnit.SECONDS, queue);
              for (int i = 0; i < 6; i++) {
                   MyThread t = new MyThread();
                   if(myThreadPool.getTaskCount() != 1)
                        myThreadPool.submit(t);
    }now see my queue size is 5 and I am submitting 6 jobs to execute. When I run main class, it runs all jobs and program never terminates.
    Output:
    This is MyThread running...
    This is MyThread running...
    This is MyThread running...
    This is MyThread running...
    This is MyThread running...
    Complted...
    This is MyThread running...
    Complted...
    Complted...
    Complted...
    Complted...
    Complted...
    Edited by: Miral on Apr 8, 2009 2:16 PM
    Edited by: Miral on Apr 8, 2009 2:17 PM
    Edited by: Miral on Apr 8, 2009 2:17 PM

  • 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 in JRT

    Hi All,
    1) the first question is what is the recommended way to allocate thread poll in rt system??
    2) what is the best way to do:
    -if my mission take a long time can i just suspend the thread and than resume it again (is it possible at all??)
    or the other option is to return it to the pool and get it again and again.
    im asking the second question from the view of performance and low latency .
    i assumed that each time i return the thread to the pool and than active it again it will "cost" cpu time.
    hope my question is clear enough.
    TIA
    Gabi

    Hi Gabi,
    I'm not completely clear on your questions. You can create a thread pool in a RT system the same basic way as in non-RT but you need to deal with priorities correctly. One way to do this would be to have the pool threads run at maximum priority normally and then drop to the actual priority of a submitted work task. Another model is to split the pool into groups based on priority, so effectively there is a work queue per priority-level and a group of threads to service each pool. This second model is used in the Real-time CORBA "lanes" approach. Designing an effective thread pool is a non-trivial task (take a look at the java.util.concurrent Thread PoolExecutor) and dealing with RT priorities and RT latency issues makes it even more complex.
    Alternatively rather than use an explicit thread pool consider whether you can convert the design to one using AsyncEvents and AsyncEventHandlers.
    Question 2 I don't really understand. Pool threads typically block on a queue waiting for work tasks to appear. But you can also have a non-terminating task that effectively picks up its own work from elsewhere - eg a task that reads from a socket to get the next "job" to process. Any interaction between threads is going to cost CPU time, whether a pool is involved or not, but yes there will be overhead associated with a pool, just as there is starting and terminating a thread, or performing any kind of thread coordination/synchronization.
    Regards,
    David Holmes

  • 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.

  • Starvation in EJB/MDB thread pool ?

    I am re-posting this article including the acronym EJB in the subject so that the EJB experts don't overlook this question. This question was moved from the JMS newsgroup to this newsgroup by a BEA moderator.
    Our application receives 10 different types of messages on one queue each. Thus we have 10 queues (MQ as a Foreign JMS provider with MDBs in a WLS). We have MDBs processing each of these queues. The producer (mainframe) that sends messages to these queues operates in batch mode.
    Option (1) Configure all MDBs in the same custom thread pool. If a blast of 500 messages arrives on one of the queues and all the threads start consuming messages, what happens to new messages that arrive on other queues ? Do they have to wait until these 500 messages are processed ? I would like someone from the BEA JMS implementation team to comment on this.
    Option (2) Configure smaller custom thread pools - one for each queue. Solves the problem above. Let us say we allocate 2 threads per MDB in custom thread pools. This ensures that none of the queues starve, however, if there is a practical limit on the maximum number of threads that can be configured, then this option introduces an inefficiency. What if there are 200 messages in one queue and zero messages in all others ? We are allowing only two threads to process those 200 messages while the other threads just sit and watch.

    I am re-posting this article including the acronym EJB in the subject so that the EJB experts don't overlook this question. This question was moved from the JMS newsgroup to this newsgroup by a BEA moderator.
    Our application receives 10 different types of messages on one queue each. Thus we have 10 queues (MQ as a Foreign JMS provider with MDBs in a WLS). We have MDBs processing each of these queues. The producer (mainframe) that sends messages to these queues operates in batch mode.
    Option (1) Configure all MDBs in the same custom thread pool. If a blast of 500 messages arrives on one of the queues and all the threads start consuming messages, what happens to new messages that arrive on other queues ? Do they have to wait until these 500 messages are processed ? I would like someone from the BEA JMS implementation team to comment on this.
    Option (2) Configure smaller custom thread pools - one for each queue. Solves the problem above. Let us say we allocate 2 threads per MDB in custom thread pools. This ensures that none of the queues starve, however, if there is a practical limit on the maximum number of threads that can be configured, then this option introduces an inefficiency. What if there are 200 messages in one queue and zero messages in all others ? We are allowing only two threads to process those 200 messages while the other threads just sit and watch.

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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?

  • Thread Pools

    Hi Everyone;
    I have a Runnable class called Page.
    during the course of my program's execution it might make 300 of these Page threads per hour. Someone suggested that I might have a performance and resource penalty for creating these threads.
    They suggested a thread pool. Does anyone know how to make a THread Pool - Or does anyone know if a Thread pool would be useful in this situation?
    Stephen

    You can make sure that a thread has been removed by using .join() to merge it with an existing thread.
    If you are creating one thread per second, then I think a thread pool is still overkill - it really does depend on the OS you are on and the speed of the machine.
    The real question is:
    1. What is the time required to create and start the thread
    2. What is the total processing time of the thread before it dies
    If #1 becomes a significant percentage of #2, AND you are having performance problems, then using a pool <b>might</b> be an appropriate strategy for improving performance.
    Later Java VMs are pretty efficient when it comes to creating threads, and thread pools have a whole host of nastiness associated with them, so I'd avoid them unless there is a really compelling (i.e. tested and confirmed) reason to do so.
    - K

  • 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…

  • 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.

  • How to create a Thread Pool

    Freinds,
    I need to create a thread pool for one of my application.My knowledge of threads is limited to beginner level. I am just looking out for some pointers that will help me to create thread pool by reading and understanding any of the availble examples.Please send and if possible explain a bit. I really appreciate the fast response from the crowd. Thanks a lot for the help.

    Hi,
    A thread pool is used in situations where you have multiple requests to be serviced and limited resources. A typical example is a server with multiple clients. The server resources are limited and you cant typically create a thread for each client. You would then pick up one of the vacant threads and process the client and put the thread back in the pool. If you dont have any free threads, then you will make the client wait till you have one.
    The typical questions you need to ask are, pool size, the kind of waiting scheme (queue, stack, prioritized queue, etc.). Additionally if you need a resizable thread pool you would need to define how the pool should shrink (abort operation and terminate or wait for operation to continue and terminate) and things like this.
    If you need a typical implementation of a thread pool, you can go to JavaGuru.com where you have a standard implementation with all relevant details explained.
    Prashanth

Maybe you are looking for