The problem of thread pool

I want to make a thread pool to handle UDP package request
so I set tow int variable :
norsize;
maxsize;
the norsize is normal amount threads when Server boot they will be creat;
the maxsize is when the quest is large and the norsize threads are not enough,The
Thead pool can increase to the amount
but how reduce the Thread pool amount when it reach the maxsize????

That was funy (the Duke Dollars part) :)
Ok. This time with some code.
We have a class that manages work. This work is made up of Runnable objects and the threads that run it. Let's go with sample code instead of english, just remenber that I wrote this code directly to the post text area and didn't event compile it, although it should work.
publi class WorkQueue {
    private LinkedList m_listRunnable;
    private int m_nMinThread;
    private int m_nMaxThread;
    private int m_nTimeOut;
    private int m_nNumThread;
    private int m_nNumThreadWaiting;
    public WorkQueue(int minThread, int maxThread, int timeOut) {
        m_listRunnable = new LinkedList();
        m_nMinThread = minThread;
        m_nMaxThread = maxThread;
        m_nTimeOut = timeOut;
        m_nNumThread = 0;
        m_nNumThreadWaiting = 0;
        init();
    private void init() {
        /* Start MinThread threads */
        for (i = 0; i < m_nMinThread; i++) {
             new WorkSlaveThread();
             m_nNumThread++;
    /* Inner class for the work thread */
    private class WorkSlaveThread extends Thread {
        public WorkSlaveThread() {
        public void run() {
            /* Work unless no work is returned, then it should stop */
            for (Runnable work = getNextWork(); work != null; work = getNextWork()) {
                try {
                    work.run();
                } catch (Throwable ex) {
                    /* Log the error */
                    ex.printStackTrace();
            threadStopping();
    private void threadStopping() {
        synchronized (this) {
            m_nNumThread--;
    private Runnable getNextWork() {
        Runnable work;
        long starttime = System.currentTimeMillis();
        long currenttime = starttime;
        long timeOut = m_nTimeOut * 1000; // Assume the time on in the constructor is in seconds
        synchronized (m_listRunnable) {
            /* Until there is work and the time out hasn't exceed */
            /* (time out ignored if the minimum umber of threads is reached) */
            while ((m_listRunnable.size() == 0) && ((timeOut > (currenttime - starttime)) || (m_nThreads == m_nMinThreads))) {
                try {
                    m_nNumThreadWaiting++;
                    m_listRunnable.wait(m_nTimeOut * 1000);
                } catch (Exception ex) {
                    /* Exception are launched if the VM is going down */
                    return null;
                } finally {
                    m_nNumThreadWaiting--;
                currenttime = System.currentTimeMillis();
            if (m_listRunnable.size () == 0) {
                /* Stop threads procedure */
                return null; // Null will stop the thread
            } else {
                work = (Runnable)m_listRunnable.remove(0);
                return work;
    public void addWork(Runnable work) {
        synchronized (m_listRunnable) {
            m_listRunnable.add(work);
            /* Start threads if necessary */
            if ((m_nNumThreadWaiting == 0) && (m_nNumThread < m_nMaxthread)) {
                new WorkSlaveThread();
                synchronized (this) {
                    m_nNumThread++;
            /* Signal a waiting thread */
            m_listRunnable.notify();
}Well, this about does it! I didn't compile this, nor this is the code I use internally (internally I have shutdown procedures to ensure all work is down and other things), but it should do all the things a mention previously (I don't think I forgot any thing).
Hope this helps,
Nuno

Similar Messages

  • The problem in the thread pool implemented by myself

    Hello, I need to a thread pool in J2ME CDC 1.0 + FP 1.0, so I implemented a simple one by myself that also meets my own requirement.
    Here is the main idea:
    The thread pool creates a fixed number of threads in advance. When a task comes, it is put in the waiting list. All threads tries to get the tasks from the waiting list. If no task exists, the threads wait until someone wakes them up.
    Here are the requirements from myself:
    1. when a task has finished its work in one execution, it is put in the waiting list for the next run.
    2. the task can control the delay between when the task owner tries to put it in the waiting list and when the task is actually put in the waiting list. I need this function because sometimes I don't want the tasks to run too often and want to save some CPU usage.
    In my program, I creates two thread pools. In one pool, every task don't use the delay, and the thread pool works very well. The other pool has the tasks that use the delay, and sometimes, as I can see from the printed information, there are many tasks in the waiting list but 0 or 1 thread executes tasks. It seems that the waiting threads cannot wake up when new tasks comes.
    I suspect the code in addTask(), but cannot find the reason why it fails. Could anyone please help me find out the bug in my code? I put the code of thread pool below
    Thank you in advance
    Zheng Da
    ThreadPool.java
    package j2me.concurrent;
    import java.util.LinkedList;
    import java.util.Timer;
    import java.util.TimerTask;
    import alvis.general.Util;
    public class ThreadPool {
         private int maxQueueSize;
         private boolean running = true;
         private Thread[] threads;
         private LinkedList tasks = new LinkedList();
         private Timer timer = new Timer(true);
         private AtomicInteger usingThreads = new AtomicInteger(0);
         private synchronized boolean isRunning() {
              return running;
         private synchronized void stopRunning() {
              running = false;
         private synchronized PoolTask getTask() {
              while (tasks.isEmpty() && isRunning()) {
                   try {
                        this.wait();
                   } catch (InterruptedException e) {
                        e.printStackTrace();
              if (tasks.isEmpty())
                   return null;
              // Util.log.info(Thread.currentThread().getName() +
              // " gets a task, left tasks: " + tasks.size());
              return (PoolTask) tasks.removeFirst();
         private synchronized void addTaskNoDelay(PoolTask task) {
              tasks.addLast(task);
              notifyAll();
         private synchronized void addTask(final PoolTask task) {
              long delay = task.delay();
              if (delay == 0) {
                   addTaskNoDelay(task);
              } else {
                   timer.schedule(new TimerTask() {
                        public void run() {
                             addTaskNoDelay(task);
                   }, delay);
         private synchronized int numTasks() {
              return tasks.size();
         private class PoolThread extends Thread {
              public void run() {
                   Util.poolThreads.inc();
                   while (isRunning()) {
                        PoolTask task = getTask();
                        if (task == null) {
                             Util.poolThreads.dec();
                             return;
                        usingThreads.inc();
                        long currentTime = System.currentTimeMillis();
                        task.run();
                        long elapsedTime = System.currentTimeMillis() - currentTime;
                        if (elapsedTime > 100)
                             System.err.println(task.toString() + " takes " + ((double) elapsedTime)/1000 + "s");
                        usingThreads.dec();
                        if (!task.finish()) {
                             addTask(task);
                   Util.poolThreads.dec();
         public ThreadPool(int size, int taskQueueSize) {
              maxQueueSize = taskQueueSize;
              threads = new Thread[size];
              for (int i = 0; i < threads.length; i++) {
                   threads[i] = new PoolThread();
                   threads.start();
         public synchronized boolean executor(PoolTask task) {
              if (!isRunning()) {
                   return false;
              Util.log.info("Thread Pool gets " + task + ", there are "
                        + numTasks() + " waiting tasks");
              if (numTasks() >= maxQueueSize) {
                   return false;
              addTask(task);
              return true;
         public synchronized void destroy() {
              stopRunning();
              timer.cancel();
              // TODO: I am not sure it can wake up all threads and destroy them.
              this.notifyAll();
         public synchronized void printSnapshot() {
              System.err.println("using threads: " + usingThreads + ", remaining tasks: " + tasks.size());
    PoolTask.javapackage j2me.concurrent;
    public interface PoolTask extends Runnable {
         * It shows if the task has already finished.
         * If it isn't, the task will be put in the thread pool for the next execution.
         * @return
         boolean finish();
         * It shows the delay in milliseconds that the task is put in the thread pool.
         * @return
         long delay();

    are receiving/sends tasks packets time consuming operation in your case or not? if it is not you do not need to use thread pools at all. you can create a queue like in your code through the linked list and dispatch this queue periodically with minimum monitor usage. try this.
    import java.util.LinkedList;
    public class PacketDispatcher extends Thread {
        LinkedList list = new LinkedList();
        public PacketDispatcher (String name) {
            super(name);
        public void putTask(Task task) {
            synchronized (list) {
                list
                        .add(task);
                list.notify();
        public void run() {
            while (true/* your condition */) {
                Task task = null;
                synchronized (list) {
                    while (list.isEmpty())
                        try {
                            list.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                    task = (Task)list
                            .poll();
                if (task == null) {
                    try {
                        Thread
                                .sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    continue;
                task
                        .run();
                if (!task.isFinished()) {
                    putTask(task);
                Thread
                        .yield();
        public static void main(String[] args) {
            // just for test
            try {
                Thread.sleep (10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            PacketDispatcher dispatcher = new PacketDispatcher("Packet Dispatcher");
            Task task = new Task();
            dispatcher.putTask(task);
            dispatcher.start();
            try {
                Thread.sleep (10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            Task task2 = new Task();
            dispatcher.putTask(task2);
    class Task {
        long result = 0;
        public boolean isFinished () {
            if (getResult() >= 10000000) {
                return true;
            return false;
        public void run() {
            for (int i = 0; i < 1000; i++) {
                result += i;
        public long getResult () {
            return result;       
    }

  • Thread pool throws reject exceptions even though the queue is not full

    Hi. I am using org.springframework.scheduling.concurrent.ThreadPo olTaskExecutor which is based on java
    java.util.concurrent.ThreadPoolExecutor
    with a enviornment under load.
    I see on some cases, that this thread pool throws tasks with reject exception
    even though the queue size is 0.
    According to the documentation, this thread pool should increase the pool size to core size and then wait untill all queue is full to create new threads.
    this is not what happends. for some reason the queue is not filled but exceptions are thrown.
    Any ideas why this can happen?

    This is the stack trace:
    taskExecutorStats-1 2010-04-27 11:01:43,324 ERROR [com.expand.expandview.infrastructure.task_executor] TaskExecutorController: RejectedExecutionException exception in thread: 18790970, failed on thread pool: [email protected]544f07, to run logic: com.expand.expandview.infrastructure.logics.DispatchLogicsProviderLogic
    org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@dd9007] did not accept task: com.expand.expandview.infrastructure.task_executor.TaskExecuterController$1@141f728; nested exception is java.util.concurrent.RejectedExecutionException
         at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:305)
         at com.expand.expandview.infrastructure.task_executor.TaskExecuterController.operate(TaskExecuterController.java:68)
         at com.expand.expandview.infrastructure.proxies.DataProxy.callLogic(DataProxy.java:131)
         at com.expand.expandview.infrastructure.proxies.DataProxy.operate(DataProxy.java:109)
         at com.expand.expandview.infrastructure.logics.AbstractLogic.operate(AbstractLogic.java:455)
         at com.expand.expandview.server.app.logics.stats.StatsPersisterSingleChunkLogic.persistSlots(StatsPersisterSingleChunkLogic.java:362)
         at com.expand.expandview.server.app.logics.stats.StatsPersisterSingleChunkLogic.doLogic(StatsPersisterSingleChunkLogic.java:132)
         at com.expand.expandview.infrastructure.logics.AbstractLogic.execute(AbstractLogic.java:98)
         at com.expand.expandview.server.app.logics.ApplicationLogic.execute(ApplicationLogic.java:79)
         at com.expand.expandview.infrastructure.task_executor.TaskExecuterControllerDirect.operate(TaskExecuterControllerDirect.java:33)
         at com.expand.expandview.infrastructure.proxies.LogicProxy.service(LogicProxy.java:62)
         at com.expand.expandview.infrastructure.logics.AbstractLogic.service(AbstractLogic.java:477)
         at com.expand.expandview.server.app.logics.stats.StatsPersisterLogic.persist(StatsPersisterLogic.java:48)
         at com.expand.expandview.server.app.logics.stats.StatsPersisterLogic.doLogic(StatsPersisterLogic.java:19)
         at com.expand.expandview.infrastructure.logics.AbstractLogic.execute(AbstractLogic.java:98)
         at com.expand.expandview.server.app.logics.ApplicationLogic.execute(ApplicationLogic.java:79)
         at com.expand.expandview.infrastructure.task_executor.TaskExecuterController$1.run(TaskExecuterController.java:80)
         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: java.util.concurrent.RejectedExecutionException
         at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1760)
         at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)
         at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)
         at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:302)
         ... 19 more

  • 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

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

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

  • 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

  • ScheduledThreadPoolExecutor core thread pool / keepalive/timing out threads

    Hi,
    I am using a ScheduledThreadPoolExecutor - java1.6 on Windows(currently).
    I would like to minimise the number of threads in the pool running at any one time to around the number of threads required to run the number of tasks that are concurrently executing.
    However, I don't seem to be able to get the thread pool to minimise the number of threads below the max threads in the constructor.
    I want to do this mainly because I have a large delay queue and the performance of the pool seems to be better when the number of threads in the pool is minimised to roughly the number of threads required to service the concurrently executing tasks.
    Any ideas?
    Thanks,
    Alex
                    ThreadFactory tf = new MyThreadFactory();
              ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(50,tf);
              scheduler.setCorePoolSize(10);
              //scheduler.setMaximumPoolSize(50);
              scheduler.setKeepAliveTime(1, TimeUnit.NANOSECONDS);
              scheduler.allowCoreThreadTimeOut(true);
              scheduler.schedule(aTask, 10, TimeUnit.SECONDS);
    ...

    because of how a scheduledthreadpoolexecutor works, it doesn't really make sense to have a variable number of threads. since threads are only added when tasks are added to the pool (aka, when submit is called), once the core threads timed out they would never get replaced (e.g. you would eventually get down to 1 thread and never get anymore added). one way to achieve what you want would be to have a single threaded ScheduledThreadPoolExecutor, where the scheduled jobs do the real work in a separate, variable size thread pool (e.g. the scheduled tasks do not do anything but submit a task to the real work thread pool). this solution would work fine for "schedule at fixed rate" but not for "schedule with fixed delay". you would actually have to simulate the latter by scheduling a one-off task which resubmits itself to the scheduler each time it completes.

  • Does thread pool really help

    Friends,
    I wanted your opinion on whether thread pools really help. Some people are of the opinion that thread pools don't really make much difference. On what basis should I make a decision whether to go for a pool or not? Is the reason that I want to limit the number of threads spawned a valid reason for pooling or it depends on the fact that for how much duration each of the threads is going to remain busy?
    Can anyone please comment?
    Thanks,
    praddyB

    sztejkat wrote:
    I have run into a similar question.
    The answer is, as usual, "it depends".
    One delegates work to worker thread if things to be done are too long to wait for completion. This is a true sentence.
    I have found that it is worth to use pool of worker threads if I need to spawn multiple, but not concurently accessing resources, lengthy tasks which should not wait for each other.
    That applies to threads. It provides no basis for pools.
    If tasks are to access same resource there is no point in getting a separate thread for each of them. One may get into many deadlocking troubles.
    Not sure what you mean by that. If you are actually deadlocking on a single resource then you are doing something weird. Deadlocks result due to multiple resources (and incorrect access).
    [http://www.javaworld.com/javaworld/jw-10-2001/jw-1012-deadlock.html]
    Blocking on the other hand occurs with a single resource. Obviously if a single resource is used exclusively or primarily in thread processing then either don't use threads or re-arch to split it up.
    Worker thread/pool is usually an application wide resource where one does throw "things to be done in background" or "things which can't hold current thread code flow".
    Threads, pooled or not, can be the primary focus of the application. I would suppose that when someone considers using a pool that in fact in almost all cases the work tasks to be done are either the primary or a substantial part of the processing.

  • Thread pool executor problem

    When using a thread pool executor (java.util.concurrent.ThreadPoolExecutor) to limit the number of threads executing at a time, the number of threads running still exceeds the limit number.
    This is the code:
    private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 3, 20, TimeUnit.SECONDS, new LinkedBlockingQueue());
    The number of tasks in my program are 4, so i always have 4 threads running, although i limited it to 3.
    Can anyone help me with this problem? Or can u propose another solution to limit the number of running threads? By the way, i also tried using a newFixedThreadPool() and got the same problem.
    Thx.

    The number of tasks in my program are 4, so i always
    have 4 threads running, although i limited it to 3.How do you know that there are 4 threads running? If you're generating a JVM thread dump, you're going to see threads that are used internally by the JVM.
    Here's a simple program that creates a fixed-size threadpool and runs jobs. It limits the number of concurrent threads to 3. Compare it to what you're doing, I'm sure that you'll find something different. Also, verify that you're not creating threads somewhere else in your program; all of the ThreadPoolExecutor threads will have names of the form "pool-X-thread-Y"
    import java.util.concurrent.Executors;
    import java.util.concurrent.ExecutorService;
    public class ThreadPoolTest {
        public static void main(String[] args) {
            ExecutorService pool = Executors.newFixedThreadPool(3);
            for (int ii = 0 ; ii < 10 ; ii++) {
                pool.execute(new MyRunnable());
            pool.shutdown();
        private static class MyRunnable implements Runnable {
            public void run() {
                log("running");
                try {
                    Thread.sleep(1000L);
                catch (InterruptedException e) {
                    log("interrupted");
            private void log(String msg) {
                System.err.println(
                        msg + " on " + Thread.currentThread().getName()
                        + " at " + System.currentTimeMillis());
    }

  • Thread Pool Problem

    Hi,
    I amhaving problem with a thread pooling my code once allocates a thread to a user then never is able to find that it is idle. the code is some what like this.
    public class foo extends Thread{
    pubblic void setPrimeData(Hashtable data){
    //sets the primary data
    run()
    this.isrunning = true;
    //does something
    this.isrunning= false;
    }

    You cannot restart a Thread. Once it has run, it cannot be reused. If you want to hand new tasks to threads in a pool, device some means by which you can hand a running (started) thread a new Runnable to execute in its run() method.
    Chuck

  • Aplication server thread pool problem

    I'm using sun app server 8.
    After some time from starting (and using) the server, it stops responding to clients.
    When I change the max number of threads on server the number of clients it can serve before hanging folows the change. So I guess that some threads are not recycled.
    But, I can't get full thread dump to see what's happening.
    Also I can't get any thread pool monitoring information through asadmin.
    (I can see that EJB's are all removed successfuly)
    Any suggestions.
    Thanks in advance.

    First of all, thank you for helping me.
    The client wasn't making problems, but server did. (I didn't said that I use the app. server on XP.)
    For now I solved the problem by installing the new beta 2004Q4. It works fine now, it also has some thread monitoring in web console...
    I was getting this, when I tried to monitor the thread-pool (it is set on HIGH):
    asadmin> get -m server.thread-pools.thread-pool.thread-pool-1.*
    No matches resulted from the wildcard expression.
    CLI137 Command get failed.
    If it means anything this is what I was getting when I do ctrl-break. (this thread dump stays the same even after server stops responding...)
    Full thread dump Java HotSpot(TM) Client VM (1.4.2_04-b04 mixed mode):
    "Thread-6" prio=5 tid=0x02edad08 nid=0xb40 runnable [331f000..331fd8c]
    at java.io.FileInputStream.readBytes(Native Method)
    at java.io.FileInputStream.read(FileInputStream.java:177)
    at org.apache.commons.launcher.StreamConnector.run(StreamConnector.java:
    115)
    "Thread-5" prio=5 tid=0x02ebbb98 nid=0x8ac runnable [32df000..32dfd8c]
    at java.io.FileInputStream.readBytes(Native Method)
    at java.io.FileInputStream.read(FileInputStream.java:194)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:220)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
    - locked <0x10089900> (a java.io.BufferedInputStream)
    at java.io.FilterInputStream.read(FilterInputStream.java:90)
    at org.apache.commons.launcher.StreamConnector.run(StreamConnector.java:
    115)
    "Signal Dispatcher" daemon prio=10 tid=0x0093dc18 nid=0x930 waiting on condition
    [0..0]
    "Finalizer" daemon prio=9 tid=0x008a5c20 nid=0xbd0 in Object.wait() [2b5f000..2b
    5fd8c]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x10502a00> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    - locked <0x10502a00> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    "Reference Handler" daemon prio=10 tid=0x008a47f0 nid=0xb4 in Object.wait() [2b1
    f000..2b1fd8c]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x10502a68> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:429)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
    - locked <0x10502a68> (a java.lang.ref.Reference$Lock)
    "main" prio=5 tid=0x000362a0 nid=0xc38 runnable [7f000..7fc3c]
    at java.lang.Win32Process.waitFor(Native Method)
    at org.apache.commons.launcher.LaunchTask.execute(LaunchTask.java:705)
    at org.apache.tools.ant.Task.perform(Task.java:341)
    at org.apache.tools.ant.Target.execute(Target.java:309)
    at org.apache.tools.ant.Target.performTasks(Target.java:336)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
    at org.apache.commons.launcher.Launcher.start(Launcher.java:402)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at LauncherBootstrap.main(LauncherBootstrap.java:185)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.sun.enterprise.admin.servermgmt.pe.PEInstancesManager.startInstan
    ce(PEInstancesManager.java:115)
    at com.sun.enterprise.admin.servermgmt.pe.PEDomainsManager.startDomain(P
    EDomainsManager.java:126)
    at com.sun.enterprise.cli.commands.StartDomainCommand.runCommand(StartDo
    mainCommand.java:59)
    at com.sun.enterprise.cli.framework.CLIMain.invokeCommand(CLIMain.java:1
    23)
    at com.sun.enterprise.cli.framework.CLIMain.main(CLIMain.java:39)
    "VM Thread" prio=5 tid=0x0093c698 nid=0x9b4 runnable
    "VM Periodic Task Thread" prio=10 tid=0x00940438 nid=0xbd4 waiting on condition
    "Suspend Checker Thread" prio=10 tid=0x0093d2b8 nid=0x2c0 runnable

  • I have been unable to publish my website due to this message "iweb quit unexpectedly - the problem may have been caused by FTP plug-in" - Iweb seems to register all pages, then crashes before publishing.Tried quite few thread trouble shoots, no luck.Help?

    I have mac book pro 10.5 Leopard
    Have just started using iweb and have small site of about 5 pages, plus blog.  I have yet been able to publish, each time I try iweb crashes and receive following note -
    The application iweb quite unexpectedly.  The problem may have been caused by the FTPKit Plug-in.
    I have tried a few troubleshooting methods recomended on other threads, ie. deleting caches, copying domain and reboots... but no luck.
    Any help very much appreciated.

    Reinstall iWeb from the source you got it from originallhy.  Or, if you're running iWeb 3 download and apply or reapply the iWeb 3.0.4 updater. It included that plugin.
    OT

  • Thread pools problem

    How do we know that a given task(implementing Callable) in a thread pool (ThreadPoolExecutor) is completed ?
    I know that we can use the get( ) method of Future class... but for that the current thread has to wait until the Task given to the Thread pool completed.
    But I want to know ..Is it possible to get (asynchronus)notification from Thread pool when one of the submitted task finish.

    What about using the isDone() method of Future or even get(timeout, TimeUnit.SECONDS).
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Future.html

  • What is the problem in my Thread Dump's output?

    Dear all,
    Below is my Thread Dump output. I can not figure out what and where is the problem of this Thread Dump's output. Could some one please give me some hints?
    Thanks alot
    Tu
    ----------------Thread Dump's Output-----------------
    Full thread dump Java HotSpot(TM) Client VM (1.5.0_07-b03 mixed mode, sharing):
    "TP-Monitor" daemon prio=1 tid=0xb0b14490 nid=0xfaa in Object.wait()
    [0xb08fe000..0xb08fee40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89433f70> (a
    org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable)
    at org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable.run(ThreadPool.java:559)
    - locked <0x89433f70> (a
    org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "TP-Processor4" daemon prio=1 tid=0xb0b13730 nid=0xfa9 runnable
    [0xb097e000..0xb097efc0]
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
    - locked <0x89438110> (a java.net.SocksSocketImpl)
    at java.net.ServerSocket.implAccept(ServerSocket.java:450)
    at java.net.ServerSocket.accept(ServerSocket.java:421)
    at org.apache.jk.common.ChannelSocket.accept(ChannelSocket.java:293)
    at org.apache.jk.common.ChannelSocket.acceptConnections(ChannelSocket.java:647)
    at org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:857)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    "TP-Processor3" daemon prio=1 tid=0xb0b0f6b8 nid=0xfa8 in
    Object.wait() [0xb09fe000..0xb09fef40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89434250> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89434250> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "TP-Processor2" daemon prio=1 tid=0xb0b0fec8 nid=0xfa7 in
    Object.wait() [0xb0a7e000..0xb0a7f0c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x894342e8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x894342e8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "TP-Processor1" daemon prio=1 tid=0xb0b14978 nid=0xfa6 in
    Object.wait() [0xb0afe000..0xb0aff040]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89434380> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89434380> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Monitor" prio=1 tid=0x08609b18 nid=0xfa5 in Object.wait()
    [0xb0cc9000..0xb0cc91c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378950> (a
    org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable)
    at org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable.run(ThreadPool.java:559)
    - locked <0x89378950> (a
    org.apache.tomcat.util.threads.ThreadPool$MonitorRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor25" daemon prio=1 tid=0x08608ce0 nid=0xfa4
    runnable [0xb0d48000..0xb0d49140]
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
    - locked <0x89010c58> (a java.net.SocksSocketImpl)
    at java.net.ServerSocket.implAccept(ServerSocket.java:450)
    at java.net.ServerSocket.accept(ServerSocket.java:421)
    at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.acceptSocket(PoolTcpEndpoint.java:407)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:70)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor24" daemon prio=1 tid=0x086085f8 nid=0xfa3 in
    Object.wait() [0xb0dc8000..0xb0dc8ec0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378ab8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378ab8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor23" daemon prio=1 tid=0x08606dd0 nid=0xfa2 in
    Object.wait() [0xb0e48000..0xb0e48e40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378b50> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378b50> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor22" daemon prio=1 tid=0x08605ed0 nid=0xfa1 in
    Object.wait() [0xb0ec8000..0xb0ec8fc0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378be8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378be8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor21" daemon prio=1 tid=0x08604fd0 nid=0xfa0 in
    Object.wait() [0xb0f48000..0xb0f48f40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378c80> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378c80> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor20" daemon prio=1 tid=0x086040f0 nid=0xf9f in
    Object.wait() [0xb0fc8000..0xb0fc90c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378d18> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378d18> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor19" daemon prio=1 tid=0x08432538 nid=0xf9e in
    Object.wait() [0xb1048000..0xb1049040]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378db0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378db0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor18" daemon prio=1 tid=0x08431638 nid=0xf9d in
    Object.wait() [0xb10c9000..0xb10c91c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378e48> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378e48> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor17" daemon prio=1 tid=0x08430738 nid=0xf9c in
    Object.wait() [0xb1148000..0xb1149140]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378ee0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378ee0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor16" daemon prio=1 tid=0x0842f838 nid=0xf9b in
    Object.wait() [0xb11c8000..0xb11c8ec0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89378f78> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89378f78> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor15" daemon prio=1 tid=0x0842e938 nid=0xf9a in
    Object.wait() [0xb1248000..0xb1248e40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379010> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379010> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor14" daemon prio=1 tid=0x0842da38 nid=0xf99 in
    Object.wait() [0xb12c8000..0xb12c8fc0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x893790a8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x893790a8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor13" daemon prio=1 tid=0x0842cb38 nid=0xf98 in
    Object.wait() [0xb1348000..0xb1348f40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379140> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379140> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor12" daemon prio=1 tid=0x0842bc50 nid=0xf97 in
    Object.wait() [0xb13c8000..0xb13c90c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x893791d8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x893791d8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor11" daemon prio=1 tid=0x084f75d0 nid=0xf96 in
    Object.wait() [0xb1448000..0xb1449040]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379270> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379270> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor10" daemon prio=1 tid=0x084f66d0 nid=0xf95 in
    Object.wait() [0xb14c9000..0xb14c91c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379308> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379308> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor9" daemon prio=1 tid=0x084f57d0 nid=0xf94 in
    Object.wait() [0xb1548000..0xb1549140]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x893793a0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x893793a0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor8" daemon prio=1 tid=0x08488970 nid=0xf93 in
    Object.wait() [0xb15c8000..0xb15c8ec0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379438> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379438> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor7" daemon prio=1 tid=0x08487a70 nid=0xf92 in
    Object.wait() [0xb1648000..0xb1648e40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x893794d0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x893794d0> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor6" daemon prio=1 tid=0x08486b90 nid=0xf91 in
    Object.wait() [0xb16c8000..0xb16c8fc0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379568> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379568> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor5" daemon prio=1 tid=0x084e3e30 nid=0xf90 in
    Object.wait() [0xb1748000..0xb1748f40]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379600> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379600> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor4" daemon prio=1 tid=0x084e2f90 nid=0xf8f in
    Object.wait() [0xb17c8000..0xb17c90c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379698> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379698> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor3" daemon prio=1 tid=0x084e2158 nid=0xf8e in
    Object.wait() [0xb1848000..0xb1849040]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379730> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379730> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor2" daemon prio=1 tid=0x085e74d0 nid=0xf8d in
    Object.wait() [0xb18c9000..0xb18c91c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x893797c8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x893797c8> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "http-8080-Processor1" daemon prio=1 tid=0x085e6638 nid=0xf8c in
    Object.wait() [0xb1948000..0xb1949140]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x89379860> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Object.wait(Object.java:474)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:656)
    - locked <0x89379860> (a
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable)
    at java.lang.Thread.run(Thread.java:595)
    "ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon prio=1
    tid=0x083719f8 nid=0xf8b waiting on condition [0xb1a85000..0xb1a85ec0]
    at java.lang.Thread.sleep(Native Method)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1547)
    at java.lang.Thread.run(Thread.java:595)
    "Low Memory Detector" daemon prio=1 tid=0x080a44f8 nid=0xf7f runnable
    [0x00000000..0x00000000]
    "CompilerThread0" daemon prio=1 tid=0x080a2f98 nid=0xf7e waiting on
    condition [0x00000000..0xb21b2928]
    "Signal Dispatcher" daemon prio=1 tid=0x080a2068 nid=0xf7d waiting on
    condition [0x00000000..0x00000000]
    "Finalizer" daemon prio=1 tid=0x0809c540 nid=0xf7c in Object.wait()
    [0xb24b2000..0xb24b3040]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x88f01de0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
    - locked <0x88f01de0> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    "Reference Handler" daemon prio=1 tid=0x0809a6b0 nid=0xf7b in
    Object.wait() [0xb2533000..0xb25331c0]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x88f01e60> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:474)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
    - locked <0x88f01e60> (a java.lang.ref.Reference$Lock)
    "main" prio=1 tid=0x0805d1c8 nid=0xf79 runnable [0xbfbd9000..0xbfbda4f8]
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384)
    - locked <0x8946f690> (a java.net.SocksSocketImpl)
    at java.net.ServerSocket.implAccept(ServerSocket.java:450)
    at java.net.ServerSocket.accept(ServerSocket.java:421)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:388)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:615)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:575)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
    "VM Thread" prio=1 tid=0x08097b58 nid=0xf7a runnable
    "VM Periodic Task Thread" prio=1 tid=0x080a5998 nid=0xf80 waiting on condition

    Thanks alot for your reply. It is a web application
    using java and tomcat server. And the problem is that
    sometime when I click on a button or a link than the
    CPU goes to 100% and it hangs but normally it works
    smoothly without any problem.This often indicates a busy retry loop somewhere. You need to acquire the thread dump when the problem occurs, but be warned that depending on the problem it may not be possible to obtain a Java-level thread dump. In that case you need to try and take an OS level thread dump - eg using pstack on solaris/linux (and there's some win32 tool as well if I recall correctly).

Maybe you are looking for